原创首发
Android13下拉菜单添加截屏以及在安兔兔中如何做假设备的参数信息
下拉菜单添加锁屏的功能,核心思路有些我也不是很明白,我也是照着系统其他下拉菜单功能做的,首先是先在vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/tiles中创建截屏功能实现的类ScreenShotTile.java,这个tiles中有很多下拉菜单功能实现的类,我们也照着加就是了,代码如下:
/*
* Copyright (c) 2016, The Android Open Source Project
* Contributed by the Paranoid Android Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Antaiui <zhuangdt> <2020-11-2> add for ScreenRecorder
*/
package com.android.systemui.qs.tiles;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.service.quicksettings.Tile;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Switch;
import androidx.annotation.Nullable;
import com.android.internal.logging.MetricsLogger;
import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.screenrecord.RecordingController;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
//import com.android.systemui.statusbar.policy.KeyguardMonitor;
import java.util.List;
import javax.inject.Inject;
import android.os.Handler;
import android.os.Looper;
/** Quick settings tile: ScreenRecorder **/
public class ScreenShotTile extends QSTileImpl<QSTile.BooleanState> {
final static String PKG = "com.android.systemui";
final static String SERVICE = "com.android.systemui.screenshot.TakeScreenshotService";
private final Icon mIcon = ResourceIcon.get(R.drawable.ic_screenshot);
//private final ActivityStarter mActivityStarter;
// private final KeyguardMonitor mKeyguard;
private RecordingController mController;
private KeyguardDismissUtil mKeyguardDismissUtil;
private long mMillisUntilFinished = 0;
@Inject
public ScreenShotTile(
QSHost host,
@Background Looper backgroundLooper,
@Main Handler mainHandler,
FalsingManager falsingManager,
MetricsLogger metricsLogger,
StatusBarStateController statusBarStateController,
ActivityStarter activityStarter,
QSLogger qsLogger,
RecordingController controller,
KeyguardDismissUtil keyguardDismissUtil ) {
super(host, backgroundLooper, mainHandler, falsingManager, metricsLogger,
statusBarStateController, activityStarter, qsLogger);
// mKeyguard = Dependency.get(KeyguardMonitor.class);
//mActivityStarter = Dependency.get(ActivityStarter.class);
mController = controller;
mKeyguardDismissUtil = keyguardDismissUtil;
}
@Override
public BooleanState newTileState() {
return new BooleanState();
}
@Override
public void handleSetListening(boolean listening) {
//DON'T CARE
}
@Override
protected void handleClick(@Nullable View view) {
//launchScreenRecorder();
mHost.forceCollapsePanels();
new Handler().postDelayed(new Runnable() {
public void run() {
Intent intent = new Intent("com.android.view.joya_screenshot");
mContext.sendBroadcast(intent);
}
},500);
}
@Override
public Intent getLongClickIntent() {
return null;
}
@Override
protected void handleLongClick(@Nullable View view) {
handleClick(view);
}
private void startScreenRecorderService(){
try {
Intent intent = new Intent();
intent.setClassName(PKG, SERVICE);
if(isSafesServiceIntent(intent)){
mContext.startService(intent);
}
} catch (Exception e) {
e.printStackTrace();
}
}
protected void launchScreenRecorder(){
startScreenRecorderService();
mHost.forceCollapsePanels();
}
private boolean isSafesServiceIntent(Intent mServiceIntent){
PackageManager packageManager = mContext.getPackageManager();
List<ResolveInfo> services = packageManager.queryIntentServices(mServiceIntent, 0);
return services.size() > 0;
}
@Override
public CharSequence getTileLabel() {
return mContext.getString(R.string.quick_settings_screenshot_label);
}
@Override
protected void handleUpdateState(BooleanState state, Object arg) {
state.value = true;
state.label = mContext.getString(R.string.quick_settings_screenshot_label);
state.icon = mIcon;
state.expandedAccessibilityClassName = Switch.class.getName();
state.contentDescription = state.label;
state.state = Tile.STATE_INACTIVE;
}
@Override
public int getMetricsCategory() {
return -1;
}
}
核心功能实现的类写完以后要添加那些图标的资源文件,路径如下:vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable/ic_screenshot.xml,代码如下:
<!--
Copyright (C) 2018 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3C19,1.9 18.1,1.01 17,1.01zM17,21H7l0,-1h10V21zM17,18H7V6h10V18zM17,4H7V3h10V4z"/>
<path
android:fillColor="#FF000000"
android:pathData="M9.5,8.5l2.5,0l0,-1.5l-2.5,0l-1.5,0l0,1.5l0,2.5l1.5,0z"/>
<path
android:fillColor="#FF000000"
android:pathData="M12,17l2.5,0l1.5,0l0,-1.5l0,-2.5l-1.5,0l0,2.5l-2.5,0z"/>
</vector>
然后就是在那些配置文件配置好截屏以及在翻译资源文件添加上截屏:
diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/strings.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/strings.xml
old mode 100644
new mode 100755
index e5aa0c0f4e5..4d345c7bde6
--- a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/strings.xml
+++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/strings.xml
@@ -2543,4 +2543,5 @@
=1 {# notification}
other {# notifications}
}</string>
+ <string name="quick_settings_screenshot_label">ScreenShot</string>
</resources>
diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-zh-rCN/strings.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-zh-rCN/strings.xml
old mode 100644
new mode 100755
index 976fa405e93..06b046386c4
--- a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-zh-rCN/strings.xml
+++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-zh-rCN/strings.xml
@@ -957,4 +957,5 @@
<string name="dream_overlay_status_bar_alarm_set" msgid="566707328356590886">"闹钟已设置"</string>
<string name="dream_overlay_status_bar_camera_mic_off" msgid="3199425257833773569">"摄像头和麦克风已关闭"</string>
<string name="dream_overlay_status_bar_notification_indicator" msgid="8091389255691081711">"{count,plural, =1{# 条通知}other{# 条通知}}"</string>
+ <string name="quick_settings_screenshot_label">截屏</string>
</resources>
下拉菜单那些功能模块的显示是在下面那个布局文件中管理的,但是也不一定就是用的vendor下面的,还有可能是用的package下面的systemui,但是更改的方法都是一样的,添加上截屏即可:
diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/config.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/config.xml
index df0975633f9..7226a109bfe 100755
--- a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/config.xml
+++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/config.xml
@@ -74,7 +74,7 @@
<!-- The default tiles to display in QuickSettings -->
<string name="quick_settings_tiles_default" translatable="false">
- wifi,internet,cell,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,location,saver,custom(com.google.android.gms/.nearby.sharing.SharingTileService)
+ wifi,internet,cell,bt,shot,flashlight,airplane,cast,screenrecord,night,wallet,rotation
</string>
<!-- The class path of the Safety Quick Settings Tile -->
@@ -87,7 +87,7 @@
<!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" -->
<string name="quick_settings_tiles_stock" translatable="false">
- internet,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness,qr_code_scanner,onehanded,color_correction
+ internet,bt,shot,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness,qr_code_scanner,onehanded,color_correction
</string>
<!-- The tiles to display in QuickSettings -->
在安卓系统systemUI快速设置面板工厂类中添加截屏的快捷方式
diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java
old mode 100644
new mode 100755
index c987283a733..cd52e081892
--- a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java
+++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java
@@ -57,6 +57,7 @@ import com.android.systemui.qs.tiles.UiModeNightTile;
import com.android.systemui.qs.tiles.WifiTile;
import com.android.systemui.qs.tiles.WorkModeTile;
import com.android.systemui.util.leak.GarbageMonitor;
+import com.android.systemui.qs.tiles.ScreenShotTile;
/// M: add plugin in quicksetting @{
import com.mediatek.systemui.ext.IQuickSettingsPlugin;
@@ -109,12 +110,15 @@ public class QSFactoryImpl implements QSFactory {
private final Lazy<QSHost> mQsHostLazy;
private final Provider<CustomTile.Builder> mCustomTileBuilderProvider;
+ private final Provider<ScreenShotTile> mScreenShotTileProvider;
+
@Inject
public QSFactoryImpl(
Lazy<QSHost> qsHostLazy,
Provider<CustomTile.Builder> customTileBuilderProvider,
Provider<WifiTile> wifiTileProvider,
+ Provider<ScreenShotTile> screenShotTileProvider,
Provider<InternetTile> internetTileProvider,
Provider<BluetoothTile> bluetoothTileProvider,
Provider<CellularTile> cellularTileProvider,
@@ -174,6 +178,7 @@ public class QSFactoryImpl implements QSFactory {
mQuickAccessWalletTileProvider = quickAccessWalletTileProvider;
mQRCodeScannerTileProvider = qrCodeScannerTileProvider;
mOneHandedModeTileProvider = oneHandedModeTileProvider;
+ mScreenShotTileProvider = screenShotTileProvider;
mColorCorrectionTileProvider = colorCorrectionTileProvider;
}
@@ -238,6 +243,8 @@ public class QSFactoryImpl implements QSFactory {
return mNightDisplayTileProvider.get();
case "nfc":
return mNfcTileProvider.get();
+ case "shot":
+ return mScreenShotTileProvider.get();
case "dark":
return mUiModeNightTileProvider.get();
case "screenrecord":
最后在phonewindowmanager.java这个类中添加一个截屏的广播,接收到截屏的广播之后就去截屏
diff --git a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index ddd3431919c..94e0307df92 100755
--- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -2069,6 +2069,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mDefaultDisplayPolicy.setDockMode(intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
Intent.EXTRA_DOCK_STATE_UNDOCKED));
}
+ IntentFilter statusbarEventFilter = new IntentFilter();
+ statusbarEventFilter.addAction("com.android.view.joya_screenshot");
+ context.registerReceiver(mStatusBarEventReceiver, statusbarEventFilter);
IntentFilter gpstime = new IntentFilter();
gpstime.addAction(Intent.ACTION_BATTERY_CHANGED);
@@ -2391,6 +2394,16 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mSingleKeyGestureDetector.addRule(new StemPrimaryKeyRule(stemPrimaryKeyGestures));
}
}
+ BroadcastReceiver mStatusBarEventReceiver = new BroadcastReceiver() {
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals("com.android.view.joya_screenshot")) {
+
+ interceptScreenshotChord(
+ TAKE_SCREENSHOT_FULLSCREEN, SCREENSHOT_KEY_OTHER, 0 /*pressDelay*/);
+ }
+ }
+ };
/**
* Read values from config.xml that may be overridden depending on
这样做完下拉菜单添加锁屏的功能就大功告成了,安兔兔做假这个其实也很容易,核心逻辑就是改掉它显示给用户展示设备参数信息的TextView就可以了,下面以4+64改成8+128,分辨率1200x2000改为1200x2560为例:
diff --git a/frameworks/base/core/java/android/widget/TextView.java b/frameworks/base/core/java/android/widget/TextView.java
old mode 100644
new mode 100755
index 23393ffe885..0505f725c37
--- a/frameworks/base/core/java/android/widget/TextView.java
+++ b/frameworks/base/core/java/android/widget/TextView.java
@@ -6100,6 +6100,92 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
((Editable) mText).append(text, start, end);
+ String pkgName = getContext().getPackageName();
+ if ("com.antutu.ABenchMark".equalsIgnoreCase(pkgName)) {
+ int textViewId = getContext().getResources().getIdentifier("item_hardware_text_desc", "id", "com.antutu.ABenchMark");
+ if(mText != null)
+ if (textViewId == getId()) {
+ try {
+ String memStr = "2304 MB";
+ //getContext().getResources().getString(getContext().getResources().getIdentifier("unit_mi_byte", "string", "com.antutu.ABenchMark"));
+ if (mText.toString().contains(memStr)) {
+ mText = mText.toString().replace("2304 MB","8192 MB");
+ setText(mText);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ String memStr2 = "64 GB";
+ if (mText.toString().contains(memStr2)) {
+ mText = mText.toString().replace("64 GB","128 GB");
+ setText(mText);
+ }
+ String sizeStr1 = "1200 x 2000";
+ if (mText.toString().contains(sizeStr1)) {
+ mText = mText.toString().replace("1200 x 2000","1200 x 2560");
+ setText(mText);
+ }
+ }
+ }
这个要根据安兔兔显示设备参数信息页面实际的数值去替换,不然是替换不成功的,那个页面的所有参数信息都是可以替换的,鲁大师做假设备信息我还没解决,不过我尝试通过改底层看能否可以鲁大师做假,等待我后续更新。