当前位置:   article > 正文

MT8385 Android 11 系统状态栏导航栏控制_android mtk 导航栏

android mtk 导航栏

项目功能:

在设置中增加状态栏和导航栏得显示隐藏控制


项目修改

1.vendor/mediatek/proprietary/packages/apps/MtkSettings/设置中修改

  1. vendor/mediatek/proprietary/packages/apps/MtkSettings/res/values/strings.xml下增加
  2. + <!-- navigation bar control -->
  3. + <string name="switch_navigation_title">Switch_BarView</string>
  4. + <string name="switch_navigation_summary">Display/Hide BarView</string>
  5. vendor/mediatek/proprietary/packages/apps/MtkSettings/res/xml/display_settings.xml 下增加
  6. + <SwitchPreference
  7. + android:key="switch_navagation"
  8. + android:title="@string/switch_navigation_title"
  9. + android:summary="@string/switch_navigation_summary" />
  10. vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/DisplaySettings.java 增加
  11. +import com.android.settings.display.SwitchNavagationPreferenceController;
  12. +controllers.add(new SwitchNavagationPreferenceController(context));
  1. vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/display/SwitchNavagationPreferenceController.java
  2. +/*
  3. + * Copyright (C) 2017 The Android Open Source Project
  4. + *
  5. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  6. + * except in compliance with the License. You may obtain a copy of the License at
  7. + *
  8. + * http://www.apache.org/licenses/LICENSE-2.0
  9. + *
  10. + * Unless required by applicable law or agreed to in writing, software distributed under the
  11. + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. + * KIND, either express or implied. See the License for the specific language governing
  13. + * permissions and limitations under the License.
  14. + */
  15. +package com.android.settings.display;
  16. +
  17. +import android.content.Context;
  18. +import android.provider.Settings;
  19. +import android.os.SystemProperties;
  20. +import android.os.RemoteException;
  21. +import androidx.preference.Preference;
  22. +import androidx.preference.SwitchPreference;
  23. +import android.content.BroadcastReceiver;
  24. +import android.content.Intent;
  25. +import android.util.Log;
  26. +import com.android.settings.R;
  27. +import com.android.settings.core.PreferenceControllerMixin;
  28. +import com.android.settingslib.core.AbstractPreferenceController;
  29. +
  30. +public class SwitchNavagationPreferenceController extends AbstractPreferenceController
  31. + implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
  32. +
  33. + private static final String TAG = "SwitchNavagationPreferenceController";
  34. +
  35. + private static final String KEY_SWITCH_NAVAGATION = "switch_navagation";
  36. +
  37. + public SwitchNavagationPreferenceController(Context context) {
  38. + super(context);
  39. + }
  40. +
  41. + @Override
  42. + public boolean isAvailable() {
  43. + return true;
  44. + }
  45. +
  46. + @Override
  47. + public String getPreferenceKey() {
  48. + return KEY_SWITCH_NAVAGATION;
  49. + }
  50. +
  51. + @Override
  52. + public boolean onPreferenceChange(Preference preference, Object newValue) {
  53. + boolean value = (Boolean) newValue;
  54. + //Settings.Secure.putInt(mContext.getContentResolver(),
  55. + // KEY_SWITCH_NAVAGATION, value ? 1 : 0);
  56. + sendToReceiver(value);
  57. + return true;
  58. + }
  59. +
  60. + @Override
  61. + public void updateState(Preference preference) {
  62. + int value = 0;
  63. + //int value = Settings.Secure.getInt(mContext.getContentResolver(),
  64. + // KEY_SWITCH_NAVAGATION, 1);
  65. + try{
  66. + String nvbshow = SystemProperties.get("persist.sys.show_bar","1");
  67. + if(nvbshow.equals("1")){
  68. + value = 1;
  69. + }else{
  70. + value = 0;
  71. + }
  72. + } catch (Exception ex) {
  73. + Log.d(TAG,"tes get nvbshow failed");
  74. + }
  75. + ((SwitchPreference) preference).setChecked(value != 0);
  76. + }
  77. +
  78. + private void sendToReceiver(boolean enable) {
  79. + Intent intent;
  80. + if(enable){
  81. + intent = new Intent("com.tes.show_bar");
  82. + }else{
  83. + intent = new Intent("com.tes.hide_bar");
  84. + }
  85. + mContext.sendBroadcast(intent);
  86. + }
  87. +
  88. +}

2.vendor/mediatek/proprietary/packages/apps/SystemUI/ 中修改

  1. vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java 增加方法
  2. + //add by max.chen 20220602 start
  3. + public void removeTesNavigationBar(){
  4. + //removeNavigationBar(DEFAULT_DISPLAY);
  5. + Display[] displays = mDisplayManager.getDisplays();
  6. + for (Display display : displays) {
  7. + removeNavigationBar(display.getDisplayId());
  8. + }
  9. + }
  10. + //add by max.chen 202206-2 end
  1. vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java中增加
  2. + //add by max.chen 20220602 start
  3. + private static final String TES_SHOW_BAR = "com.tes.show_bar";
  4. + private static final String TES_HIDE_BAR = "com.tes.hide_bar";
  5. + //add by max.chen 20220602 end
  6. +
  7. + //add by max.chen 20220602 start
  8. + //createNavigationBar(result);
  9. + try{
  10. + //persist.sys.show_bar 1:display 0:hide
  11. + String nvbshow = SystemProperties.get("persist.sys.show_bar","1");
  12. + if(nvbshow.equals("1")){
  13. + mStatusBarWindowController.setForceStatusBarVisible(true);
  14. + mPhoneStatusBarWindow.setVisibility(View.VISIBLE);
  15. + Log.d(TAG,"display navigation bar");
  16. + createNavigationBar(result);
  17. +
  18. + }else{
  19. + Log.d(TAG,"hide navigation bar");
  20. + mStatusBarWindowController.setForceStatusBarVisible(false);
  21. + mPhoneStatusBarWindow.setVisibility(View.GONE);
  22. +
  23. + }
  24. + } catch (Exception ex) {
  25. + Log.d(TAG,"tes set PhoneStatusBarWindow failed");
  26. + }
  27. - createNavigationBar(result);
  28. 广播中增加
  29. + filter.addAction(TES_SHOW_BAR);
  30. + filter.addAction(TES_HIDE_BAR);
  31. private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver()方法中增加
  32. + RegisterStatusBarResult result = null;
  33. + try {
  34. + result = mBarService.registerStatusBar(mCommandQueue);
  35. + } catch (RemoteException ex) {
  36. + ex.rethrowFromSystemServer();
  37. + }
  38. + //add by max.chen 20220602 start
  39. + else if(TES_SHOW_BAR.equals(action)) {
  40. + NavigationBarView mNavigationBarView = mNavigationBarController.getDefaultNavigationBarView();
  41. + if(mNavigationBarView != null) return;
  42. + mStatusBarWindowController.setForceStatusBarVisible(true);
  43. + mPhoneStatusBarWindow.setVisibility(View.VISIBLE);
  44. + createNavigationBar(result);
  45. + SystemProperties.set("persist.sys.show_bar","1");
  46. + }
  47. + else if(TES_HIDE_BAR.equals(action)) {
  48. + NavigationBarView mNavigationBarView = mNavigationBarController.getDefaultNavigationBarView();
  49. + if(mNavigationBarView == null) return;
  50. + mNavigationBarController.removeTesNavigationBar();
  51. + SystemProperties.set("persist.sys.show_bar","0");
  52. + mStatusBarWindowController.setForceStatusBarVisible(false);
  53. + mPhoneStatusBarWindow.setVisibility(View.GONE);
  54. + }
  55. + //add by max.chen 20220602 end

3.增加platform_app对System_property的设置权限

device/mediatek/sepolicy/basic/plat_private/platform_app.te

+get_prop(platform_app, system_prop)
+set_prop(platform_app, system_prop)

  1. device/mediatek/sepolicy/basic/plat_private/platform_app.te 增加
  2. +get_prop(platform_app, system_prop)
  3. +set_prop(platform_app, system_prop)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/219310
推荐阅读
相关标签
  

闽ICP备14008679号