Android 12.0 adds screenshot function in pull-down status bar
Recently, we received a request from a customer to add a screenshot function to the drop-down status bar and support long screenshots. The specific modification points are as follows:
1. Create a new ic_screenshot.xml file in the /vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable directory:
<!-- 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.01 zM17,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>
2. Create a new ScreenShotTile.java file in the /vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/tiles directory:
/* * 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. */ package com.android.systemui.qs.tiles; import static android.view.WindowManager.ScreenshotSource.SCREENSHOT_GLOBAL_ACTIONS; import android.content.Context; import android.content.Intent; import android.os.Handler; import android.os.Looper; import android.provider.Settings; import android.service.quicksettings.Tile; import android.view.View; import androidx.annotation.Nullable; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.systemui.R; import com.android.systemui.broadcast.BroadcastDispatcher; 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.BooleanState; 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.internal.util.ScreenshotHelper; import android.view.IWindowManager; import android.view.WindowManager; import javax.inject.Inject; /** Quick settings tile: Enable/Disable NFC **/ public class ScreenShotTile extends QSTileImpl<BooleanState> { private static final String NFC = "ScreenShotTile"; private final Icon mIcon = ResourceIcon.get(R.drawable.ic_screenshot); //private final ActivityStarter mActivityStarter; @Inject public ScreenShotTile( QSHost host, @Background Looper backgroundLooper, @Main Handler mainHandler, FalsingManager falsingManager, MetricsLogger metricsLogger, StatusBarStateController statusBarStateController, ActivityStarter activityStarter, QSLogger qsLogger, BroadcastDispatcher broadcastDispatcher ) { super(host, backgroundLooper, mainHandler, falsingManager, metricsLogger, statusBarStateController, activityStarter, qsLogger); //mActivityStarter = activityStarter; } @Override public BooleanState newTileState() { return new BooleanState(); } @Override public void handleSetListening(boolean listening) { super.handleSetListening(listening); } @Override public boolean isAvailable() { return true; } @Override protected void handleUserSwitch(int newUserId) { } @Override public Intent getLongClickIntent() { return new Intent(); } @Override protected void handleClick(@Nullable View view) { mActivityStarter.postStartActivityDismissingKeyguard( getLongClickIntent(), 0); new Handler().postDelayed(new Runnable() { @Override public void run() { ScreenshotHelper screenshotHelper = new ScreenshotHelper(mContext); screenshotHelper.takeScreenshot(WindowManager.TAKE_SCREENSHOT_FULLSCREEN, true, true, SCREENSHOT_GLOBAL_ACTIONS, new Handler(Looper.getMainLooper()), null); } }, 800);//500 } @Override public CharSequence getTileLabel() { return mContext.getString(R.string.global_action_screenshot); } @Override protected void handleUpdateState(BooleanState state, Object arg) { state.icon = mIcon; state.label = mContext.getString(R.string.global_action_screenshot); } @Override public int getMetricsCategory() { return MetricsEvent.QS_SCREENSHOT; } @Override protected String composeChangeAnnouncement() { return mContext.getString(R.string.global_action_screenshot); } }
3./vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/qs/tileimpl/QSFactoryImpl.java:
+ import com.android.systemui.qs.tiles.ScreenShotTile; + private final Provider<ScreenShotTile> mScreenShotTileProvider; public QSFactoryImpl( + Provider<ScreenShotTile> screenShotTileProvider, Provider<QuickAccessWalletTile> quickAccessWalletTileProvider) { + mScreenShotTileProvider = screenShotTileProvider; switch (tileSpec) { + case "screenshot": + return mScreenShotTileProvider.get();
4./frameworks/base/proto/src/metrics_constants/metrics_constants.proto:
// ---- End Q Constants, all Q constants go above this line ---- // Add new aosp constants above this line. //END OF AOSP CONSTANTS + QS_SCREENSHOT = 1751;
5./vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/config.xml:
<!-- The default tiles to display in QuickSettings --> <string name="quick_settings_tiles_default" translatable="false"> - wifi,cell,bt,flashlight,location,airplane,dnd,night,alarm,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle + wifi,cell,bt,screenshot,flashlight,location,airplane,dnd,night,alarm,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle </string> <!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" --> <string name="quick_settings_tiles_stock" translatable="false"> - internet,wifi,cell,bt,flashlight,dnd,alarm,airplane,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness + internet,wifi,cell,bt,flashlight,dnd,alarm,airplane,screenshot,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse ,reduce_brightness </string>
Recompile and verify, the modification takes effect, and the screenshot function has been added to the drop-down status bar.