SystemUI常见问题修改方法

AndroidO,AndroidP SystemUI问题修改笔记

  1. 修改NavigationBar ‘back’ 触控范围
    SystemUI/src/com/android/systemui/statusbar/phone/NearestTouchFrame.java
    @VisibleForTesting
    NearestTouchFrame(Context context, AttributeSet attrs, Configuration c) {
        super(context, attrs);
        //mIsActive = c.smallestScreenWidthDp < 600;
        mIsActive = false
    }
  1. 修改阿拉伯语布局NavigationBar顺序
    只需要修改config.xml中如下值的顺序即可(ps:图片需要单独修改)
<string name="config_navBarLayout" translatable="false">left,recent;home;back,rightstring>
  1. back按键的处理在onBackPressed()方法中
    SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
 /**
     * Notifies this manager that the back button has been pressed.
     *
     * @param hideImmediately Hide bouncer when {@code true}, keep it around otherwise.
     *                        Non-scrimmed bouncers have a special animation tied to the expansion
     *                        of the notification panel.
     * @return whether the back press has been handled
     */
    public boolean onBackPressed(boolean hideImmediately) {
        Log.d(TAG, "onBackPressed()");
        if (mBouncer.isShowing()) {
            mStatusBar.endAffordanceLaunch();
            reset(true/*hideImmediately*/);//add by [email protected] for defect 7216010
            ///M : fix ALPS01852958, clear mAfterKeyguardGoneAction when leaving bouncer.
            mAfterKeyguardGoneAction = null ;
            return true;
        }
        if (DEBUG) Log.d(TAG, "onBackPressed() - reset & return false");
        return false;
    }
  1. screen pinnerUI处理需要修改如下两个值
    res/values/dimens.xml
<dimen name="screen_pinning_request_button_height">85dpdimen>
<dimen name="screen_pinning_request_nav_icon_padding">0dpdimen>
  1. 隐藏MTK原生的SIM ME LOCK需要修改
    SystemUI/src/com/android/keyguard/KeyguardSecurityModel.java
    其中注释// check ME required,修改其中一个值为false就行了
   public boolean isPinPukOrMeRequiredOfPhoneId(int phoneId) {
        KeyguardUpdateMonitor updateMonitor = KeyguardUpdateMonitor.getInstance(mContext);
        if (updateMonitor != null) {
            final IccCardConstants.State simState = updateMonitor.getSimStateOfPhoneId(phoneId);

            Log.d(TAG, "isPinPukOrMeRequiredOfSubId() - phoneId = " + phoneId +
                       ", simState = " + simState) ;
            return (
                // check PIN required
                (simState == IccCardConstants.State.PIN_REQUIRED
                && !updateMonitor.getPinPukMeDismissFlagOfPhoneId(phoneId))
                // check PUK required
                || (simState == IccCardConstants.State.PUK_REQUIRED
                && !updateMonitor.getPinPukMeDismissFlagOfPhoneId(phoneId)
                && updateMonitor.getRetryPukCountOfPhoneId(phoneId) != 0)
                // check ME required
                || (simState == IccCardConstants.State.NETWORK_LOCKED
                && !updateMonitor.getPinPukMeDismissFlagOfPhoneId(phoneId)
                && updateMonitor.getSimMeLeftRetryCountOfPhoneId(phoneId) != 0
                && KeyguardUtils.isMediatekSimMeLockSupport()
                && !updateMonitor.getSimmeDismissFlagOfPhoneId(phoneId)
                && KeyguardUtils.isSimMeLockValid(phoneId)&&isShowSimMeLock)
                );
        } else {
            return false;
        }
    }
  1. 锁屏界面底部shortcut图标启动应用涉及到如下几个类
    SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
private void launchMessage() {
        Intent messageIntent = new Intent();
        mActivityStarter.startActivity(messageIntent, true);
    }

SystemUI/src/com/android/systemui/ActivityStarterDelegate.java

 @Override
    public void startActivity(Intent intent, boolean dismissShade, Callback callback) {
        if (mActualStarter == null) return;
        mActualStarter.startActivity(intent, dismissShade, callback);
    }

SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

@Override
    public void startActivity(Intent intent, boolean dismissShade, Callback callback) {
        startActivityDismissingKeyguard(intent, false, dismissShade, callback);
    }
    //隐藏NotificationPanelView
    mStatusBarView.collapsePanel(true, false /* delayed */, 100.0f /* speedUpFactor */);
  1. 禁用锁屏代码
 private void setLockScreenisDisable(){
       LockPatternUtils lockPatternUtils = new LockPatternUtils(mContext);
       if(lockPatternUtils == null)return;
        boolean isOTA;
        try {
          if(AppGlobals.getPackageManager() == null)return;
          isOTA = AppGlobals.getPackageManager().isUpgrade();
          Log.d(TAG,"setLockScreenisDisable...isOTA = :"+isOTA+",isLockScreenDisable = :"+(lockPatternUtils.isLockScreenDisabled(UserHandle.USER_OWNER))+",!ro.lockscreen.disable.default = :"+(!(SystemProperties.getBoolean("ro.lockscreen.disable.default", false))));
           } catch (RemoteException e) {
              throw new IllegalStateException("Package manager not available");
             }
         if(lockPatternUtils.isLockScreenDisabled(UserHandle.USER_OWNER) && isOTA && !(SystemProperties.getBoolean("ro.lockscreen.disable.default", false))){
               lockPatternUtils.setLockScreenDisabled(false, UserHandle.USER_OWNER);
           }
    }
  1. 插拔SIM卡之后,原来的pin/password/pattern会缩小,原因是Android原生没有考虑锁屏加入其他
    buncer的情况
    SystemUI/src/com/android/keyguard/KeyguardSecurityViewFlipper.java
@Override
    protected void onMeasure(int widthSpec, int heightSpec) {
        ....
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            //add by [email protected] for defect 7485624 begin
            if(child.getVisibility() == View.INVISIBLE || child.getVisibility() == View.GONE){
                  continue;
            }
            //add by [email protected] for defect 7485624 end
          ......
        }
  1. Home键在PhoneWindowManager.java中的调用
void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard)
  1. 中文或者日语中使用plurals类型字符串不管单数复数都只会使用other,不会区分单复数,使用plurals时要特别注意中文和日语
  2. 隐藏QuickSettings代码

SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java

                if (mBouncer.isShowing()) {
                    if (mShowing) {
                        mStatusBar.hideKeyguard();
                        mBouncer.hide(false /* destroyView */);
                        KeyguardUpdateMonitor.getInstance(mContext).sendKeyguardReset();
                        updateStates();
                    }
    }
  1. SIM卡的View和password的View都在一个父类里面,未插SIM卡测量的寬高和插了SIM卡测量的寬高发生了变化导致password向上浮动,添加:android:layout_gravity=“bottom”
    SystemUI/res-keyguard/layout/keyguard_password_view.xml
<com.android.keyguard.KeyguardPasswordView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/res-auto"
    android:id="@+id/keyguard_password_view"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    androidprv:layout_maxWidth="@dimen/keyguard_security_width"
    androidprv:layout_maxHeight="@dimen/keyguard_security_height"
    android:gravity="bottom"
    >
  1. framework层有关锁屏密码长度的代码
    services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
//PasswordMetrics 存储密码的矩阵
public void setActivePasswordState(PasswordMetrics metrics, int userHandle)
  1. 定制默认锁屏壁纸需求
    SystemUI/res-keyguard/drawable-xhdpi/default_lock_wallpaper.jpg
    SystemUI/src/com/android/systemui/statusbar/phone/LockscreenWallpaper.java
public LockscreenWallpaper(Context ctx, StatusBar bar, Handler h) {
 ......
 //add by [email protected] for defect 9245999 begin
        if(isFristBoot()){
                mWallpaperManager.setStream(
                        mContext.getResources().openRawResource(R.drawable.default_lock_wallpaper),
                        null,
                        true,
                        WallpaperManager.FLAG_LOCK);
                Settings.System.putInt(mContext.getContentResolver(), "isDefaultWallpaper",1);
                }else{
                Settings.System.putInt(mContext.getContentResolver(), "isDefaultWallpaper",0);
                }

        //add by [email protected] for defect 9245999 begin
        } catch (RemoteException e) {
            Log.e(TAG, "System dead?" + e);
        } catch (IOException e) {
            Log.e(TAG, "Exception = :" + e);
        }
    }
  }
     //add by [email protected] for defect 9245999 begin
  private boolean isFristBoot(){
    IPackageManager pm = AppGlobals.getPackageManager();
        try {
            return pm.isFirstBoot();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
    }
  }
  //add by [email protected] for defect 9245999 end

//frameworks/base/core/java/android/app/WallpaperManager.java
 public ParcelFileDescriptor getWallpaperFile(@SetWallpaperFlags int which, int userId) {
        //add by [email protected] for defect 9245999 begin
          if(Settings.System.getInt(mContext.getContentResolver(), "isDefaultWallpaper",-1)==1 && which==2){
             String pkg = mContext.getPackageName();
             if(pkg.startsWith("com.android.cts") || pkg.startsWith("com.android.vts") || pkg.contains("gts"))
             return null;
          }
        //add by [email protected] for defect 9245999 end
	......
}
  1. 插入SIM卡,点击Emergency之后再返回SIM PIN界面,QuickSettings会下拉下来
    SystemUI常见问题修改方法_第1张图片
    修改代码
    SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
public void expand(final boolean animate){
 ......
  getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        if (!mInstantExpanding) {
                            getViewTreeObserver().removeOnGlobalLayoutListener(this);
                            return;
                        }//add by [email protected] for defect 7226148 begin
                        if (mStatusBar.getStatusBarWindow().getHeight()
                                != mStatusBar.getStatusBarHeight()&&!mStatusBar.isBouncerShowing()
                                || (mStatusBar.isKeyguardSecure() ?
                                        mStatusBar.getBarState() != StatusBarState.SHADE : true)) {
                         //add by [email protected] for defect 7226148 end
 ......
}
  1. 锁屏notification渐变度设置
    vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
private void updateNotificationTranslucency() {
        float alpha = 1f;
        if (mClosingWithAlphaFadeOut && !mExpandingFromHeadsUp &&
                !mHeadsUpManager.hasPinnedHeadsUp()) {
            alpha = getFadeoutAlpha();
        }
        if (mBarState == StatusBarState.KEYGUARD && !mHintAnimationRunning) {
            alpha *= mClockPositionResult.clockAlpha;
        }
        //add by [email protected] for defect 8503312 begin
        if(!mUnlockMethodCache.isMethodSecure() && mNotificationStackScroller.getAlpha() != 1 && mNotificationStackScroller.getAlpha() != 0){
           mStatusBar.getLockIcon().setAlpha(alpha);
        }
         //add by [email protected] for defect 8503312 end
        mNotificationStackScroller.setAlpha(alpha);
    }
  1. StatusBar状态设置代码在StatusBarWindowController的apply方法里,包括高度,宽度:
private void apply(State state) {
        applyKeyguardFlags(state);
        applyForceStatusBarVisibleFlag(state);
        applyFocusableFlag(state);
        applyForceShowNavigationFlag(state);
        adjustScreenOrientation(state);
        applyHeight(state);
        applyUserActivityTimeout(state);
        applyInputFeatures(state);
        applyFitsSystemWindows(state);
        applyModalFlag(state);
        applyBrightness(state);
        applyHasTopUi(state);
        applyNotTouchable(state);
        applyStatusBarColorSpaceAgnosticFlag(state);
        if (mLp != null && mLp.copyFrom(mLpChanged) != 0) {
            //寬高封装在mLp
            mWindowManager.updateViewLayout(mStatusBarView, mLp);
        }
        if (mHasTopUi != mHasTopUiChanged) {
            try {
                mActivityManager.setHasTopUi(mHasTopUiChanged);
            } catch (RemoteException e) {
                Log.e(TAG, "Failed to call setHasTopUi", e);
            }
            mHasTopUi = mHasTopUiChanged;
        }
        notifyStateChangedCallbacks();
    }

你可能感兴趣的:(笔记)