直接貼修改記錄
diff --git a/vendor/mediatek/proprietary/packages/apps/MtkSettings/AndroidManifest.xml b/vendor/mediatek/proprietary/packages/apps/MtkSettings/AndroidManifest.xml
index 4be16ea..b968c3c 100755
--- a/vendor/mediatek/proprietary/packages/apps/MtkSettings/AndroidManifest.xml
+++ b/vendor/mediatek/proprietary/packages/apps/MtkSettings/AndroidManifest.xml
@@ -3372,6 +3372,14 @@
</intent-filter>
</receiver>
+ <service
+ android:name=".ClearDefaultLauncherService"
+ android:enabled="true">
+ <intent-filter>
+ <action android:name="com.hwapu.shutdown.ClearDefaultLauncherService"/>
+ </intent-filter>
+ </service>
+
<!-- Couldn't be triggered from outside of settings. Statsd can trigger it because we send
PendingIntent to it-->
<receiver android:name=".fuelgauge.batterytip.AnomalyDetectionReceiver"
diff --git a/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/ClearDefaultLauncherService.java b/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/ClearDefaultLauncherService.java
new file mode 100644
index 0000000..d2e0e79
--- /dev/null
+++ b/vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/ClearDefaultLauncherService.java
@@ -0,0 +1,166 @@
+package com.android.settings;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.app.Service;
+import android.content.Intent;
+import android.content.ComponentName;
+import android.content.pm.ResolveInfo;
+import android.content.pm.PackageManager;
+import android.content.IntentFilter;
+import android.hardware.input.InputManager;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.SystemClock;
+import android.util.Log;
+import android.view.InputDevice;
+import android.view.KeyCharacterMap;
+import android.view.KeyEvent;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+
+public class ClearDefaultLauncherService extends Service {
+
+ final private String TAG = "ClearDefaultLauncherService";
+ private long mDownTime = 0;
+
+ @Override
+ public IBinder onBind(Intent arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void onCreate() {
+ // TODO Auto-generated method stub
+ super.onCreate();
+ }
+
+ @Override
+ public void onDestroy() {
+ // TODO Auto-generated method stub
+ super.onDestroy();
+ }
+
+ @Override
+ public void onStart(Intent intent, int startId) {
+
+ if(intent != null){
+ Bundle bundle = intent.getExtras();
+ if(bundle != null){
+ String packageName = bundle.getString("package");
+ String className = bundle.getString("class");
+ Boolean bSendHomeKey = bundle.getBoolean("sendHome",true);
+ // SystemProperties.set("persist.sys.def_launcherpag", DefaultPackageName);
+ // SystemProperties.set("persist.sys.def_launchercls", DefaultClassName);
+
+ Log.i(TAG , "DefaultPackageName ="+packageName);
+ Log.i(TAG, "DefaultClassName ="+className);
+
+ PackageManager pm = getPackageManager();
+
+ // take all launcher activity
+ intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(Intent.CATEGORY_HOME);
+ List<ResolveInfo> list = new ArrayList<ResolveInfo>();
+ list = pm.queryIntentActivities(intent, 0);
+ if (list != null) {
+ int size = list.size();
+ int k = 0;
+ for (int j = 0; j < size; j++) {
+ final ResolveInfo r = list.get(j);
+ Log.d(TAG, "launcher activity" + j + " "
+ + r.activityInfo.packageName);
+ if (r.activityInfo.packageName.equals(packageName))
+ k = 1;
+ }
+ if (k != 1) {
+ Log.d(TAG, "return take all launcher activity");
+ return;
+ }
+ }
+
+ // remove defautl launcher
+ ArrayList<IntentFilter> intentList = new ArrayList<IntentFilter>();
+ ArrayList<ComponentName> cnList = new ArrayList<ComponentName>();
+ getPackageManager().getPreferredActivities(intentList, cnList,
+ null);
+ IntentFilter dhIF = null;
+ for (int i = 0; i < cnList.size(); i++) {
+ dhIF = intentList.get(i);
+ if (dhIF.hasAction(Intent.ACTION_MAIN)
+ && dhIF.hasCategory(Intent.CATEGORY_HOME)) {
+ Log.d(TAG, "remove defautl Launcher "
+ + cnList.get(i).getPackageName());
+ getPackageManager().clearPackagePreferredActivities(
+ cnList.get(i).getPackageName());
+ }
+ }
+
+ // set defautl launcher
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_MAIN);
+ filter.addCategory(Intent.CATEGORY_HOME);
+ filter.addCategory(Intent.CATEGORY_DEFAULT);
+ final int N = list.size();
+ ComponentName launcher = new ComponentName(packageName, className);
+ ComponentName[] set = new ComponentName[N];
+ int defaultMatch = 0;
+ for (int i = 0; i < N; i++) {
+ ResolveInfo r = list.get(i);
+ set[i] = new ComponentName(r.activityInfo.packageName,
+ r.activityInfo.name);
+ if (launcher.getClassName().equals(r.activityInfo.name)) {
+ defaultMatch = r.match;
+ }
+ }
+ Log.d(TAG, "set defautl Launcher " + packageName);
+ pm.addPreferredActivity(filter, defaultMatch, set, launcher);
+
+ if(bSendHomeKey){
+ SetDefault();
+ }
+ }
+ }
+
+ // TODO Auto-generated method stub
+
+ super.onStart(intent, startId);
+ }
+
+
+ void sendEvent(int action, int flags) {
+ sendEvent(action, flags, SystemClock.uptimeMillis());
+ }
+
+ void sendEvent(int action, int flags, long when) {
+ final int repeatCount = (flags & KeyEvent.FLAG_LONG_PRESS) != 0 ? 1 : 0;
+ final KeyEvent ev = new KeyEvent(mDownTime, when, action, KeyEvent.KEYCODE_HOME, repeatCount,
+ 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0,
+ flags | KeyEvent.FLAG_FROM_SYSTEM | KeyEvent.FLAG_VIRTUAL_HARD_KEY,
+ InputDevice.SOURCE_KEYBOARD);
+ InputManager.getInstance().injectInputEvent(ev,
+ InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
+ }
+
+ public void SetDefault() {
+
+ mDownTime = SystemClock.uptimeMillis();
+
+ //send home key
+ sendEvent(KeyEvent.ACTION_DOWN, 0, mDownTime);
+
+ sendEvent(KeyEvent.ACTION_UP, 0);
+ }
+
+ private void reboot(){
+ Intent intent = new Intent(Intent.ACTION_REBOOT);
+ intent.putExtra("nowait",1);
+ intent.putExtra("interval",1);
+ intent.putExtra("window",0);
+ sendBroadcast(intent);
+ }
+
+
+}
Android9.0新增設置默認桌面服務
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.