900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > java usb 断开_Android P开发者选项中的USB调试关闭

java usb 断开_Android P开发者选项中的USB调试关闭

时间:2021-09-17 18:41:25

相关推荐

java usb 断开_Android P开发者选项中的USB调试关闭

根据字符查找到开发者选项的字符是:reset_dashboard_title

packages/apps/Settings/res/xml/system_dashboard_fragment.xml

找到对应system_dashboard_fragment.xml调用的Java文件是:

packages/apps/Settings/src/com/android/settings/system/SystemDashboardFragment.java

进而找到:

packages/apps/Settings/src/com/android/settings/system/DashboardFragmentRegistry.java

static {

PARENT_TO_CATEGORY_KEY_MAP = new ArrayMap<>();

PARENT_TO_CATEGORY_KEY_MAP.put(

NetworkDashboardFragment.class.getName(), CategoryKey.CATEGORY_NETWORK);

PARENT_TO_CATEGORY_KEY_MAP.put(ConnectedDeviceDashboardFragment.class.getName(),

CategoryKey.CATEGORY_CONNECT);

PARENT_TO_CATEGORY_KEY_MAP.put(AdvancedConnectedDeviceDashboardFragment.class.getName(),

CategoryKey.CATEGORY_DEVICE);

PARENT_TO_CATEGORY_KEY_MAP.put(AppAndNotificationDashboardFragment.class.getName(),

CategoryKey.CATEGORY_APPS);

PARENT_TO_CATEGORY_KEY_MAP.put(PowerUsageSummary.class.getName(),

CategoryKey.CATEGORY_BATTERY);

PARENT_TO_CATEGORY_KEY_MAP.put(DefaultAppSettings.class.getName(),

CategoryKey.CATEGORY_APPS_DEFAULT);

PARENT_TO_CATEGORY_KEY_MAP.put(DisplaySettings.class.getName(),

CategoryKey.CATEGORY_DISPLAY);

PARENT_TO_CATEGORY_KEY_MAP.put(SoundSettings.class.getName(),

CategoryKey.CATEGORY_SOUND);

PARENT_TO_CATEGORY_KEY_MAP.put(StorageDashboardFragment.class.getName(),

CategoryKey.CATEGORY_STORAGE);

PARENT_TO_CATEGORY_KEY_MAP.put(SecuritySettings.class.getName(),

CategoryKey.CATEGORY_SECURITY);

PARENT_TO_CATEGORY_KEY_MAP.put(AccountDetailDashboardFragment.class.getName(),

CategoryKey.CATEGORY_ACCOUNT_DETAIL);

PARENT_TO_CATEGORY_KEY_MAP.put(AccountDashboardFragment.class.getName(),

CategoryKey.CATEGORY_ACCOUNT);

PARENT_TO_CATEGORY_KEY_MAP.put(

SystemDashboardFragment.class.getName(), CategoryKey.CATEGORY_SYSTEM);

PARENT_TO_CATEGORY_KEY_MAP.put(LanguageAndInputSettings.class.getName(),

CategoryKey.CATEGORY_SYSTEM_LANGUAGE);

PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettingsDashboardFragment.class.getName(),

CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);

PARENT_TO_CATEGORY_KEY_MAP.put(ConfigureNotificationSettings.class.getName(),

CategoryKey.CATEGORY_NOTIFICATIONS);

PARENT_TO_CATEGORY_KEY_MAP.put(LockscreenDashboardFragment.class.getName(),

CategoryKey.CATEGORY_SECURITY_LOCKSCREEN);

PARENT_TO_CATEGORY_KEY_MAP.put(ZenModeSettings.class.getName(),

CategoryKey.CATEGORY_DO_NOT_DISTURB);

PARENT_TO_CATEGORY_KEY_MAP.put(GestureSettings.class.getName(),

CategoryKey.CATEGORY_GESTURES);

PARENT_TO_CATEGORY_KEY_MAP.put(NightDisplaySettings.class.getName(),

CategoryKey.CATEGORY_NIGHT_DISPLAY);

CATEGORY_KEY_TO_PARENT_MAP = new ArrayMap<>(PARENT_TO_CATEGORY_KEY_MAP.size());

for (Map.Entry parentToKey : PARENT_TO_CATEGORY_KEY_MAP.entrySet()) {

CATEGORY_KEY_TO_PARENT_MAP.put(parentToKey.getValue(), parentToKey.getKey());

}

}

以上见名知意,可以查看到DevelopmentSettingsDashboardFragment.java即为开发者选项的文件。

进入菜单时候初始化是否是开发者模式:

@Override

public void onActivityCreated(Bundle icicle) {

super.onActivityCreated(icicle);

// Apply page-level restrictions

setIfOnlyAvailableForAdmins(true);

if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) {

// Block access to developer options if the user is not the owner, if user policy

// restricts it, or if the device has not been provisioned

mIsAvailable = false;

// Show error message

if (!isUiRestrictedByOnlyAdmin()) {

getEmptyTextView().setText(R.string.development_settings_not_available);

}

getPreferenceScreen().removeAll();

return;

}

// Set up master switch

mSwitchBar = ((SettingsActivity) getActivity()).getSwitchBar();

mSwitchBarController = new DevelopmentSwitchBarController(

this /* DevelopmentSettings */, mSwitchBar, mIsAvailable, getLifecycle());

mSwitchBar.show();

// Restore UI state based on whether developer options is enabled

if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {

enableDeveloperOptions();

} else {

disableDeveloperOptions();

}

}

private void enableDeveloperOptions() {

if (Utils.isMonkeyRunning()) {

return;

}

DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), true);

for (AbstractPreferenceController controller : mPreferenceControllers) {

if (controller instanceof DeveloperOptionsPreferenceController) {

((DeveloperOptionsPreferenceController) controller).onDeveloperOptionsEnabled();

}

}

}

private void disableDeveloperOptions() {

if (Utils.isMonkeyRunning()) {

return;

}

DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(getContext(), false);

final SystemPropPoker poker = SystemPropPoker.getInstance();

poker.blockPokes();

for (AbstractPreferenceController controller : mPreferenceControllers) {

if (controller instanceof DeveloperOptionsPreferenceController) {

((DeveloperOptionsPreferenceController) controller)

.onDeveloperOptionsDisabled();

}

}

poker.unblockPokes();

poker.poke();

}

DevelopmentSettingsEnabler.java文件中:

判断开发者模式是否开启:

public static final String DEVELOPMENT_SETTINGS_CHANGED_ACTION =

"com.android.settingslib.development.DevelopmentSettingsEnabler.SETTINGS_CHANGED";

private DevelopmentSettingsEnabler() {

}

public static void setDevelopmentSettingsEnabled(Context context, boolean enable) {

Settings.Global.putInt(context.getContentResolver(),

Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, enable ? 1 : 0);

LocalBroadcastManager.getInstance(context)

.sendBroadcast(new Intent(DEVELOPMENT_SETTINGS_CHANGED_ACTION));

}

public static boolean isDevelopmentSettingsEnabled(Context context) {

final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);

final boolean settingEnabled = Settings.Global.getInt(context.getContentResolver(),

Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,

Build.TYPE.equals("eng") ? 1 : 0) != 0;

final boolean hasRestriction = um.hasUserRestriction(

UserManager.DISALLOW_DEBUGGING_FEATURES);

final boolean isAdminOrDemo = um.isAdminUser() || um.isDemoUser();

return isAdminOrDemo && !hasRestriction && settingEnabled;

}

对应的布局文件是:packages/apps/Settings/res/xml/development_settings.xml

android:key="debug_debugging_category"

android:title="@string/debug_debugging_category"

android:order="200">

android:key="enable_adb"

android:title="@string/enable_adb"

android:summary="@string/enable_adb_summary" />

android:title="@string/clear_adb_keys" />

android:key="enable_terminal"

android:title="@string/enable_terminal_title"

android:summary="@string/enable_terminal_summary" />

....省略较多代码

其对应的实现位于:

frameworks/base/packages/SettingsLib/src/com/android/settingslib/development/AbstractEnableAdbPreferenceController.java

对应ADB的开关如下:

private boolean isAdbEnabled() {

final ContentResolver cr = mContext.getContentResolver();

return Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, ADB_SETTING_OFF)

!= ADB_SETTING_OFF;

}

然后在设置中查找对应的默认参数即可。

frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

private void loadSecureSettings(SQLiteDatabase db) {

SQLiteStatement stmt = null;

try {

stmt = pileStatement("INSERT OR IGNORE INTO secure(name,value)"

+ " VALUES(?,?);");

loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,

R.string.def_location_providers_allowed);

// Don't do this. The SystemServer will initialize ADB_ENABLED from a

// persistent system property instead.

//loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);

// Allow mock locations default, based on build

loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,

"1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);

....//省略较多代码

根据以上注释重新查找persistent 中属性的位置:

build/make/core/main.mk

user_variant := $(filter user userdebug,$(TARGET_BUILD_VARIANT))

enable_target_debugging := true

tags_to_install :=

ifneq (,$(user_variant))

# Target is secure in user builds.

ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1

ADDITIONAL_DEFAULT_PROPERTIES += security.perf_harden=1

ifeq ($(user_variant),user)

ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1

endif

ifeq ($(user_variant),userdebug)

# Pick up some extra useful tools

tags_to_install += debug

else

# Disable debugging in plain user builds.

enable_target_debugging :=

endif

# Disallow mock locations by default for user builds

ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0

else # !user_variant

# Turn on checkjni for non-user builds.

ADDITIONAL_BUILD_PROPERTIES += ro.kernel.android.checkjni=0

# Set device insecure for non-user builds.

ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0

# Allow mock locations by default for non user builds

ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1

endif # !user_variant

ifeq (true,$(strip $(enable_target_debugging)))

# Target is more debuggable and adbd is on by default

ifeq ($(user_variant),user)

ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0

else

ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1

endif

# Enable Dalvik lock contention logging.

ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500

# Include the debugging/testing OTA keys in this build.

INCLUDE_TEST_OTA_KEYS := true

else # !enable_target_debugging

# Target is less debuggable and adbd is off by default

ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0

endif # !enable_target_debugging

此处应该就是默认是否debug的位置;

本文地址:/liuminx/article/details/107174848

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。