diff options
-rw-r--r-- | res/values/cm_strings.xml | 3 | ||||
-rw-r--r-- | res/xml/device_info_settings.xml | 9 | ||||
-rw-r--r-- | src/com/android/settings/DeviceInfoSettings.java | 33 |
3 files changed, 45 insertions, 0 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 3638d90..6c076c8 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -56,6 +56,9 @@ <string name="build_date">Build date</string> <string name="build_date_default" translatable="false">2015-01-01-0000</string> + <!-- CM Updater --> + <string name="cmupdate_settings_title">CyanogenMod updates</string> + <!-- Themes Settings --> <!-- Settings main menu entry --> <string name="themes_settings_title">Themes</string> diff --git a/res/xml/device_info_settings.xml b/res/xml/device_info_settings.xml index d3e3316..a3dad73 100644 --- a/res/xml/device_info_settings.xml +++ b/res/xml/device_info_settings.xml @@ -33,6 +33,15 @@ android:targetClass="@string/additional_system_update_menu" /> </PreferenceScreen> + <!-- CyanogenMod Updates --> + <PreferenceScreen android:key="cm_updates" + android:title="@string/cmupdate_settings_title" + android:summary="@string/system_update_settings_list_item_summary"> + <intent android:action="android.intent.action.MAIN" + android:targetPackage="com.cyanogenmod.updater" + android:targetClass="com.cyanogenmod.updater.UpdatesSettings" /> + </PreferenceScreen> + <!-- Device status - launches activity --> <PreferenceScreen android:key="status_info" android:title="@string/device_status" diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java index 3dc6446..5921fef 100644 --- a/src/com/android/settings/DeviceInfoSettings.java +++ b/src/com/android/settings/DeviceInfoSettings.java @@ -20,7 +20,9 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.os.Build; import android.os.Bundle; @@ -85,6 +87,7 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In private static final String KEY_MOD_VERSION = "mod_version"; private static final String KEY_MOD_BUILD_DATE = "build_date"; private static final String KEY_MOD_API_LEVEL = "mod_api_level"; + private static final String KEY_CM_UPDATES = "cm_updates"; static final int TAPS_TO_BE_A_DEVELOPER = 7; @@ -150,6 +153,13 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In removePreferenceIfPropertyMissing(getPreferenceScreen(), KEY_SELINUX_STATUS, PROPERTY_SELINUX_STATUS); + // Only the owner should see the Updater settings, if it exists + if (UserHandle.myUserId() == UserHandle.USER_OWNER) { + removePreferenceIfPackageNotInstalled(findPreference(KEY_CM_UPDATES)); + } else { + getPreferenceScreen().removePreference(findPreference(KEY_CM_UPDATES)); + } + // Remove Safety information preference if PROPERTY_URL_SAFETYLEGAL is not set removePreferenceIfPropertyMissing(getPreferenceScreen(), KEY_SAFETY_LEGAL, PROPERTY_URL_SAFETYLEGAL); @@ -541,5 +551,28 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment implements In } }; + private boolean removePreferenceIfPackageNotInstalled(Preference preference) { + String intentUri=((PreferenceScreen) preference).getIntent().toUri(1); + Pattern pattern = Pattern.compile("component=([^/]+)/"); + Matcher matcher = pattern.matcher(intentUri); + + String packageName=matcher.find()?matcher.group(1):null; + if(packageName != null) { + try { + PackageInfo pi = getPackageManager().getPackageInfo(packageName, + PackageManager.GET_ACTIVITIES); + if (!pi.applicationInfo.enabled) { + Log.e(LOG_TAG,"package "+packageName+" is disabled, hiding preference."); + getPreferenceScreen().removePreference(preference); + return true; + } + } catch (NameNotFoundException e) { + Log.e(LOG_TAG,"package "+packageName+" not installed, hiding preference."); + getPreferenceScreen().removePreference(preference); + return true; + } + } + return false; + } } |