RK3288[android 7.1]调试笔记 在下拉菜单下增加关机重启快捷键功能

21 篇文章 5 订阅
18 篇文章 7 订阅

RK3288[android 7.1]调试笔记 在下拉菜单下增加关机重启快捷键

1 在路径为/frameworks/base/packages/SystemUI/res/values/config.xml文件中增加下拉菜单重启关机快捷键

wangxd@build-server-100:~/work/dsy/rk3288-Android-7.0/frameworks/base(m_android_7_0)$ git diff packages/SystemUI/res/values/config.xml
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
old mode 100644
new mode 100755
index da5f4bf..63e2788
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -100,12 +100,12 @@
 
     <!-- The default tiles to display in QuickSettings -->
     <string name="quick_settings_tiles_default" translatable="false">
-         wifi,cell,battery,dnd,flashlight,rotation,bt,airplane
+       wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,reset,shutdown
     </string>
 
     <!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" -->
     <string name="quick_settings_tiles_stock" translatable="false">
-  wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,location,hotspot,inversion,saver,work,cast,night
     
+ wifi,cell,battery,dnd,flashlight,rotation,bt,airplane,location,hotspot,inversion,saver,work,cast,night,reset,shutdown
     </string>
 
     <!-- The tiles to display in QuickSettings -->

2 在路径为/frameworks/base/packages/SystemUI/res/values/strings.xml文件中增加下拉菜单显示的字符串的布局

wangxd@build-server-100:~/work/dsy/rk3288-Android-7.0/frameworks/base(m_android_7_0)$ git diff packages/SystemUI/res/values/strings.xml
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
old mode 100644
new mode 100755
index 4a51329..81095e4
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -44,6 +44,10 @@
         <item quantity="other">%d screens in Overview</item>
     </plurals>
 

+    <string name="quick_settings_shutdown">关机</string> <!--add by dsy for reset sh
+    <string name="quick_settings_reset">重启</string> <!--add by dsy for reset shutd

     <!-- The label in the bar at the top of the status bar when there are no notifications
          showing.  [CHAR LIMIT=40]-->
     <string name="status_bar_no_notifications_title">No notifications</string>

3 在路径为/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java 文件中增加重启关机快捷键相关实现的方法

wangxd@build-server-100:~/work/dsy/rk3288-Android-7.0/frameworks/base(m_android_7_0)$ git diff packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java b/packages/System
old mode 100644
new mode 100755
index 82ed3ae..a1353e7
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
@@ -41,6 +41,10 @@ import com.android.systemui.qs.external.CustomTile;
 import com.android.systemui.qs.external.TileLifecycleManager;
 import com.android.systemui.qs.external.TileServices;
 import com.android.systemui.qs.tiles.AirplaneModeTile;
+//add by dsy for reset shutdown start
+import com.android.systemui.qs.tiles.ResetTile;
+import com.android.systemui.qs.tiles.ShutdownTile;
+//add by dsy for reset shutdown end 
 import com.android.systemui.qs.tiles.BatteryTile;
 import com.android.systemui.qs.tiles.BluetoothTile;
 import com.android.systemui.qs.tiles.CastTile;

@@ -432,6 +447,11 @@ public class QSTileHost implements QSTile.Host, Tunable {
         else if (tileSpec.equals("battery")) return new BatteryTile(this);
         else if (tileSpec.equals("saver")) return new DataSaverTile(this);
         else if (tileSpec.equals("night")) return new NightDisplayTile(this);
+        //add by dsy for reset shutdown start  
+        else if (tileSpec.equals("reset")) return new ResetTile(this);
+        else if (tileSpec.equals("shutdown")) return new ShutdownTile(this);
+        //add by dsy for reset shutdown end  
         
         // Intent tiles.
         else if (tileSpec.startsWith(IntentTile.PREFIX)) return IntentTile.create(this,tileSpec);
         else if (tileSpec.startsWith(CustomTile.PREFIX)) return CustomTile.create(this,tileSpec);

4 增加实现重启关机的java文件

wangxd@build-server-100:~/work/dsy/rk3288-Android-7.0/frameworks/base(m_android_7_0)$ git status
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        packages/SystemUI/res/drawable-hdpi/ic_qs_reset.png //这个是增加的重启图标
        packages/SystemUI/res/drawable-hdpi/ic_qs_shutdown.png //这个是增加的关机图标
        packages/SystemUI/src/com/android/systemui/qs/tiles/ResetTile.java //这个是增加的重启方法java文件
        packages/SystemUI/src/com/android/systemui/qs/tiles/ShutdownTile.java这个是增加的关机方法java文件

4.1在路径为
/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_qs_reset.png 增加重启图标
4.2 在路径为 /frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_qs_shutdown.png 增加关机图标
4.3 在路径为frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/ResetTile.java增加的重启方法java文件

以下就是重启的java文件内容

wangxd@build-server-100:~/work/dsy/rk3288-Android-7.0/frameworks/base(m_android_7_0)$ vim  packages/SystemUI/src/com/android/systemui/qs/tiles/ResetTile.java



package com.android.systemui.qs.tiles;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
import android.widget.Switch;
package com.android.systemui.qs.tiles;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
import android.widget.Switch;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.systemui.R;
import com.android.systemui.SystemUI;
import com.android.systemui.qs.QSTile;
import android.app.ActivityManager;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.provider.MediaStore;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.widget.Switch;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.android.systemui.R;
import android.content.Intent;
import android.util.Log;
import android.content.Context;
import com.android.internal.logging.MetricsLogger;
import android.content.ServiceConnection;
import android.content.ComponentName;
import android.os.Message;
import android.os.Messenger;
import android.os.Handler;
import android.os.IBinder;
import android.os.UserHandle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.widget.Switch;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settingslib.BatteryInfo;
import com.android.settingslib.graph.UsageView;
import com.android.systemui.BatteryMeterDrawable;
import com.android.systemui.R;
import com.android.systemui.qs.QSTile;
import com.android.systemui.statusbar.policy.BatteryController;
import java.text.NumberFormat;


public class ResetTile extends QSTile<QSTile.BooleanState>  {
    private boolean resetState;

    public boolean resetState() {
        return resetState;
    }

    public void setResetState(boolean resetState) {
        this.resetState = resetState;
    }

   public ResetTile(Host host) {
        super(host);
    }


    @Override
    public BooleanState newTileState() {
        return new BooleanState();
    }

    @Override
    protected void handleClick() {//短按事件
     //   android.util.Log.i("elink" , "click");
        Intent localIntent = new Intent("android.intent.action.REBOOT");
            localIntent.putExtra("android.intent.extra.KEY_CONFIRM", false);
            localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(localIntent);
    }

    @Override
    public CharSequence getTileLabel() {//下拉菜单显示前面定义string.xml中的“重启”的字符串
        return mContext.getString(R.string.quick_settings_reset);
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {//更新状态
       state.label = mContext.getString(R.string.quick_settings_reset);//获取前面定义string.xml中的“重启”的字符串
        state.icon = state.icon = ResourceIcon.get(R.drawable.ic_qs_reset);// 获取路径为/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_qs_reset.png 增加的重启图标
        state.value = false;
        state.expandedAccessibilityClassName = Switch.class.getName();
    }

    @Override
    public int getMetricsCategory() {//这个需要在frameworks\base\proto\src\metrics_constants.proto文件中增加返回值 后面会提到
        return MetricsEvent.QS_RESET;
    }



    @Override
    public Intent getLongClickIntent() {//长按事件
        return new Intent(Intent.ACTION_REBOOT);
    }

    @Override
    protected void setListening(boolean listening) {

    }

}


4.4 在路径为frameworks/base/packages/SystemUI/src/com/android/systemui/qs/tiles/ShutdownTile.java增加的重启方法的java文件
以下就是重启方法的java文件的内容

wangxd@build-server-100:~/work/dsy/rk3288-Android-7.0/frameworks/base(m_android_7_0)$ vim packages/SystemUI/src/com/android/systemui/qs/tiles/ShutdownTile.java

package com.android.systemui.qs.tiles;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.util.Log;
import android.widget.Switch;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.systemui.R;
import com.android.systemui.SystemUI;
import com.android.systemui.qs.QSTile;
import android.app.ActivityManager;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.provider.MediaStore;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.widget.Switch;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.android.systemui.R;
import android.content.Intent;
import android.util.Log;
import android.content.Context;
import com.android.internal.logging.MetricsLogger;
import android.content.ServiceConnection;
import android.content.ComponentName;
import android.os.Message;
import android.os.Messenger;
import android.os.Handler;
import android.os.IBinder;
import android.os.UserHandle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.widget.Switch;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settingslib.BatteryInfo;
import com.android.settingslib.graph.UsageView;
import com.android.systemui.BatteryMeterDrawable;
import com.android.systemui.R;
import com.android.systemui.qs.QSTile;
import com.android.systemui.statusbar.policy.BatteryController;
import java.text.NumberFormat;




public class ShutdownTile extends QSTile<QSTile.BooleanState>  {

    private boolean shutdownState;

    public boolean shutdownState() {
       return shutdownState;
    }

    public void setShutdownState(boolean shutdownState) {
        this.shutdownState = shutdownState;
    }

    public ShutdownTile(Host host) {
        super(host);
    }


    @Override
    public BooleanState newTileState() {
        return new BooleanState();
    }

    @Override
    protected void handleClick() {//短按事件
      //  android.util.Log.i("elink" , "click2");
        Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
            intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
            intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
    }

    @Override
    public CharSequence getTileLabel() {//下拉菜单显示前面定义string.xml中的“关机”的字符串
       return mContext.getString(R.string.quick_settings_shutdown);
    }

    @Override
    protected void handleUpdateState(BooleanState state, Object arg) {//更新状态
        state.label = mContext.getString(R.string.quick_settings_shutdown);//获取前面定义string.xml中的“关机”的字符串
        state.icon = state.icon = ResourceIcon.get(R.drawable.ic_qs_shutdown);// 获取路径为/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_qs_shutdown.png 增加的关机图标
        state.value = false;
        state.expandedAccessibilityClassName = Switch.class.getName();
    }

    @Override
    public int getMetricsCategory() {//这个需要在frameworks\base\proto\src\metrics_constants.proto文件中增加返回值 后面会提到
        return MetricsEvent.QS_SHUTDOWN;
    }



    @Override
    public Intent getLongClickIntent() {//长按事件
        return new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
    }

    @Override
    protected void setListening(boolean listening) {

    }
}

5 需要在路径为frameworks\base\proto\src\metrics_constants.proto文件中增加相关返回值

wangxd@build-server-100:~/work/dsy/rk3288-Android-7.0/frameworks/base(m_android_7_0)$ git diff proto/src/metrics_constants.proto
diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto
old mode 100644
new mode 100755
index ff3a9c5..173ef36
--- a/proto/src/metrics_constants.proto
+++ b/proto/src/metrics_constants.proto
@@ -2248,6 +2248,10 @@ message MetricsEvent {
     // ---- End N-MR2 Constants, all N-MR2 constants go above this line ----
 
     // Add new aosp constants above this line.
+    //add by dsy for reset shutdown start 
+    QS_RESET=744;
+    QS_SHUTDOWN=745;
+    //add by dsy for reset shutdown end 
     // END OF AOSP CONSTANTS
   }
 }

6 需要在路径为/frameworks/base/api/current.txt 中增加相关API接口函数
在路径为/frameworks/base/api/system-current.txt 中增加相关API接口函数
在路径为/frameworks/base/api//test-current.txt 中增加相关API接口函数

1 在路径为/frameworks/base/api/current.txt  中增加相关API接口函数

wangxd@build-server-100:~/work/dsy/rk3288-Android-7.0/frameworks/base(m_android_7_0)$ git diff
diff --git a/api/current.txt b/api/current.txt
old mode 100644
new mode 100755
index 81b5260..5c36c3a
--- a/api/current.txt
+++ b/api/current.txt
@@ -8636,6 +8636,10 @@ package android.content {
     field public static final java.lang.String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_PO
     field public static final java.lang.String ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION
     field public static final java.lang.String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER
+
+    field public static final java.lang.String ACTION_REBOOT = "android.intent.action.REBOOT";
+    field public static final java.lang.String ACTION_SHUTDOWN = "android.intent.action.SHUTDOWN";
+
     field public static final java.lang.String ACTION_PROCESS_TEXT = "android.intent.action.PROCESS_TEXT
     field public static final java.lang.String ACTION_PROVIDER_CHANGED = "android.intent.action.PROVIDER
     field public static final java.lang.String ACTION_QUICK_CLOCK = "android.intent.action.QUICK_CLOCK";

2 在路径为/frameworks/base/api/system-current.txt  中增加相关API接口函数

diff --git a/api/system-current.txt b/api/system-current.txt
old mode 100644
new mode 100755
index 9f8f336..3f4d555
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -8979,6 +8979,10 @@ package android.content {
     field public static final java.lang.String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_PO
     field public static final java.lang.String ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION
     field public static final java.lang.String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER
+
+    field public static final java.lang.String ACTION_REBOOT = "android.intent.action.REBOOT";
+    field public static final java.lang.String ACTION_SHUTDOWN = "android.intent.action.SHUTDOWN";
+ 
    field public static final java.lang.String ACTION_PROCESS_TEXT = "android.intent.action.PROCESS_TEXT
     field public static final java.lang.String ACTION_PROVIDER_CHANGED = "android.intent.action.PROVIDER
     field public static final java.lang.String ACTION_QUERY_PACKAGE_RESTART = "android.intent.action.QUE
    
    3 在路径为/frameworks/base/api//test-current.txt  中增加相关API接口函数 
diff --git a/api/test-current.txt b/api/test-current.txt
old mode 100644
new mode 100755
index 8f69c4b..8ede0ec
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -8648,6 +8648,10 @@ package android.content {
     field public static final java.lang.String ACTION_POWER_CONNECTED = "android.intent.action.ACTION_PO
     field public static final java.lang.String ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION
     field public static final java.lang.String ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER
+
+    field public static final java.lang.String ACTION_REBOOT = "android.intent.action.REBOOT";
+    field public static final java.lang.String ACTION_SHUTDOWN = "android.intent.action.SHUTDOWN";
+
     field public static final java.lang.String ACTION_PROCESS_TEXT = "android.intent.action.PROCESS_TEXT
     field public static final java.lang.String ACTION_PROVIDER_CHANGED = "android.intent.action.PROVIDER
     field public static final java.lang.String ACTION_QUICK_CLOCK = "android.intent.action.QUICK_CLOCK";
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值