Android P平台 :http://androidxref.com/9.0.0_r3/
1. Settings 界面打开,流程大致如下:
111 void setLocationEnabled(boolean enabled) { // 从数据库拿值,看下此刻的 LOCATION_MODE 112 final int currentMode = Settings.Secure.getInt(mContext.getContentResolver(), 113 Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF); 114 115 if (isRestricted()) { ---> 当前用户是否有权限 116 // Location toggling disabled by user restriction. Read the current location mode to 117 // update the location master switch. 118 if (Log.isLoggable(TAG, Log.INFO)) { 119 Log.i(TAG, "Restricted user, not setting location mode"); 120 } 121 if (mListener != null) { 122 mListener.onLocationModeChanged(currentMode, true); 123 } 124 return; 125 } // 主要看下这个地方 126 updateLocationEnabled(mContext, enabled, UserHandle.myUserId(), 127 Settings.Secure.LOCATION_CHANGER_SYSTEM_SETTINGS); 128 refreshLocationMode(); 129 }

最低0.47元/天 解锁文章
1339






