android.provider.Settings.Secure Java Examples

The following examples show how to use android.provider.Settings.Secure. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CbDataSender.java    From PressureNet-SDK with MIT License 6 votes vote down vote up
/**
 * Get a hash'd device ID
 * 
 * @return
 */
public String getID() {
	try {
		MessageDigest md = MessageDigest.getInstance("MD5");

		String actual_id = Secure.getString(context
				.getContentResolver(), Secure.ANDROID_ID);
		byte[] bytes = actual_id.getBytes();
		byte[] digest = md.digest(bytes);
		StringBuffer hexString = new StringBuffer();
		for (int i = 0; i < digest.length; i++) {
			hexString.append(Integer.toHexString(0xFF & digest[i]));
		}
		return hexString.toString();
	} catch (Exception e) {
		return "--";
	}
}
 
Example #2
Source File: PermissionManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public static boolean isLocationEnabled(Context context) {
    if (VERSION.SDK_INT >= 19) {
        try {
            if (Secure.getInt(context.getContentResolver(), "location_mode") != 0) {
                return true;
            }
            return false;
        } catch (SettingNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    } else if (TextUtils.isEmpty(Secure.getString(context.getContentResolver(), "location_providers_allowed"))) {
        return false;
    } else {
        return true;
    }
}
 
Example #3
Source File: DalvikDeviceService.java    From attach with GNU General Public License v3.0 6 votes vote down vote up
public String getUuid() {
    final SharedPreferences prefs = activity.getSharedPreferences(PREFS_FILE, 0);
    String uuid = prefs.getString(PREFS_DEVICE_ID, null);
    if (uuid != null) {
        if (debug) {
            Log.v(TAG, String.format("Retrieved uuid from shared prefs: %s", uuid));
        }
        return uuid;
    }

    final String androidId = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID);
    uuid = UUID.nameUUIDFromBytes(androidId.getBytes()).toString();
    if (debug) {
        Log.v(TAG, String.format("Storing uuid in shared prefs for future reference: %s", uuid));
    }
    prefs.edit().putString(PREFS_DEVICE_ID, uuid).commit();
    return uuid;
}
 
Example #4
Source File: MainActivity.java    From Moticons with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    if (!appPreferences.getDeviceID().equals(Secure.getString(context.getContentResolver(), Secure.ANDROID_ID))) {
        AlertDialog.Builder alertDialog = UtilsDialog.showDialog(context, "ಠ_ಠ", getResources().getString(R.string.dialog_wrong_id_description));
        alertDialog.setPositiveButton(android.R.string.ok + "..." + " (>_<)", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                appPreferences.setMoticoins(0);
                appPreferences.setMoticonUnlocked(new HashSet<String>());
                appPreferences.setUnlockAllMoticons(false);
                appPreferences.setRemoveAds(false);
                updateMoticoins(context);
                dialogInterface.dismiss();
            }
        });

        alertDialog.show();
    }
}
 
Example #5
Source File: BarometerNetworkActivity.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set a unique identifier so that updates from the same user are seen as
 * updates and not new data.
 */
private void setId() {
	try {
		MessageDigest md = MessageDigest.getInstance("MD5");

		String actual_id = Secure.getString(getApplicationContext()
				.getContentResolver(), Secure.ANDROID_ID);
		byte[] bytes = actual_id.getBytes();
		byte[] digest = md.digest(bytes);
		StringBuffer hexString = new StringBuffer();
		for (int i = 0; i < digest.length; i++) {
			hexString.append(Integer.toHexString(0xFF & digest[i]));
		}
		android_id = hexString.toString();
	} catch (Exception e) {
		// e.printStackTrace();
	}
}
 
Example #6
Source File: LockSettingsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public String getStringUnchecked(String key, String defaultValue, int userId) {
    if (Settings.Secure.LOCK_PATTERN_ENABLED.equals(key)) {
        long ident = Binder.clearCallingIdentity();
        try {
            return mLockPatternUtils.isLockPatternEnabled(userId) ? "1" : "0";
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }

    if (userId == USER_FRP) {
        return getFrpStringUnchecked(key);
    }

    if (LockPatternUtils.LEGACY_LOCK_PATTERN_ENABLED.equals(key)) {
        key = Settings.Secure.LOCK_PATTERN_ENABLED;
    }

    return mStorage.readKeyValue(key, defaultValue, userId);
}
 
Example #7
Source File: LockSettingsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** Do not hold any of the locks from this service when calling. */
private boolean shouldCacheSpForUser(@UserIdInt int userId) {
    // Before the user setup has completed, an admin could be installed that requires the SP to
    // be cached (see below).
    if (Settings.Secure.getIntForUser(mContext.getContentResolver(),
                Settings.Secure.USER_SETUP_COMPLETE, 0, userId) == 0) {
        return true;
    }

    // If the user has an admin which can perform an untrusted credential reset, the SP needs to
    // be cached. If there isn't a DevicePolicyManager then there can't be an admin in the first
    // place so caching is not necessary.
    final DevicePolicyManagerInternal dpmi = LocalServices.getService(
            DevicePolicyManagerInternal.class);
    if (dpmi == null) {
        return false;
    }
    return dpmi.canUserHaveUntrustedCredentialReset(userId);
}
 
Example #8
Source File: Identity.java    From Android-Commons with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an identifier that is unique for this device
 *
 * The identifier is usually reset when performing a factory reset on the device
 *
 * On devices with multi-user capabilities, each user usually has their own identifier
 *
 * In general, you may not use this identifier for advertising purposes
 *
 * @param context a context reference
 * @return the unique identifier
 */
@SuppressLint("NewApi")
public static String getDeviceId(final Context context) {
	if (mDeviceId == null) {
		final String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

		if (androidId != null && !androidId.equals("") && !androidId.equalsIgnoreCase("9774d56d682e549c")) {
			mDeviceId = androidId;
		}
		else {
			if (Build.VERSION.SDK_INT >= 9) {
				if (Build.SERIAL != null && !Build.SERIAL.equals("")) {
					mDeviceId = Build.SERIAL;
				}
				else {
					mDeviceId = getInstallationId(context);
				}
			}
			else {
				mDeviceId = getInstallationId(context);
			}
		}
	}

	return mDeviceId;
}
 
Example #9
Source File: CurrentConditionsActivity.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
public String getID() {
	try {
		MessageDigest md = MessageDigest.getInstance("MD5");

		String actual_id = Secure.getString(getApplicationContext()
				.getContentResolver(), Secure.ANDROID_ID);
		byte[] bytes = actual_id.getBytes();
		byte[] digest = md.digest(bytes);
		StringBuffer hexString = new StringBuffer();
		for (int i = 0; i < digest.length; i++) {
			hexString.append(Integer.toHexString(0xFF & digest[i]));
		}
		return hexString.toString();
	} catch (Exception e) {
		return "--";
	}
}
 
Example #10
Source File: NotificationManagerCompat.java    From letv with Apache License 2.0 6 votes vote down vote up
public static Set<String> getEnabledListenerPackages(Context context) {
    String enabledNotificationListeners = Secure.getString(context.getContentResolver(), SETTING_ENABLED_NOTIFICATION_LISTENERS);
    if (!(enabledNotificationListeners == null || enabledNotificationListeners.equals(sEnabledNotificationListeners))) {
        String[] components = enabledNotificationListeners.split(NetworkUtils.DELIMITER_COLON);
        Set<String> packageNames = new HashSet(components.length);
        for (String component : components) {
            ComponentName componentName = ComponentName.unflattenFromString(component);
            if (componentName != null) {
                packageNames.add(componentName.getPackageName());
            }
        }
        synchronized (sEnabledNotificationListenersLock) {
            sEnabledNotificationListenerPackages = packageNames;
            sEnabledNotificationListeners = enabledNotificationListeners;
        }
    }
    return sEnabledNotificationListenerPackages;
}
 
Example #11
Source File: AndroidLicensing.java    From vpn-over-dns with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void checkLicense( FREContext freContext, Context context, String publicKey )
{
    // Log.i("vpnoverdns", "checkLicense()");
	// This sample code uses Secure.ANDROID_ID only for device identification. Strenthen this string by using as many device specific
	// string so as to make it as unique as possible as this is used for obfuscating the server response.
		
	// ANDROID_ID is a 64-bit number (as a hex string) that is randomly generated on the device's first boot and should remain 
	// constant for the lifetime of the device. This value may change if a factory reset is performed on the device.  
	String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

	// Library calls this callback when it's done verifying with Android licensing server
	mLicenseCheckerCallback =  new AndroidLicenseCheckerCallback(freContext);
	
	// Construct the LicenseChecker object with a policy and call checkAccess(). In case a developer wants to change the policy to
	// be used he needs to replace  the "ServerManagedPolicy" with the policy name with any other policy, if required. 
	// ServerManagedPolicy is defined in License Verification Library (LVL) provided by android. 

	// ServerManagedPolicy policy = new ServerManagedPolicy(context, new AESObfuscator(SALT, context.getPackageName(), deviceId));
	StrictPolicy policy = new StrictPolicy();
	
	mChecker = new LicenseChecker(context, policy, publicKey);
	mChecker.checkAccess(mLicenseCheckerCallback);
}
 
Example #12
Source File: Tools.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
public static String getDeviceId(Context context) {

		TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		if (tm == null) {
			return "0_0";
		}

		StringBuffer sb = new StringBuffer();
		String imei = tm.getDeviceId();
		sb.append(TextUtils.isEmpty(imei) ? "0" : imei);
		sb.append("_");

		String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
		sb.append(TextUtils.isEmpty(androidId) ? "0" : androidId);

		return sb.toString();
	}
 
Example #13
Source File: PhoneUtils.java    From Mobilyzer with Apache License 2.0 6 votes vote down vote up
private String getDeviceId() {
	String deviceId=null;
	if(ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE)==PackageManager.PERMISSION_GRANTED){
		// This ID is permanent to a physical phone.
		deviceId = telephonyManager.getDeviceId();
	}



	// "generic" means the emulator.
	if (deviceId == null || Build.DEVICE.equals("generic")) {

		// This ID changes on OS reinstall/factory reset.
		deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
	}

	return deviceId;
}
 
Example #14
Source File: C2DMRegistrationReceiver.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
	String action = intent.getAction();
	Log.w("C2DM", "Registration Receiver called");
	if ("com.google.android.c2dm.intent.REGISTRATION".equals(action)) {
		Log.w("C2DM", "Received registration ID");
		final String registrationId = intent
				.getStringExtra("registration_id");
		String error = intent.getStringExtra("error");

		Log.d("C2DM", "dmControl: registrationId = " + registrationId
				+ ", error = " + error);
		String deviceId = Secure.getString(context.getContentResolver(),
				Secure.ANDROID_ID);
		createNotification(context, registrationId);
		sendRegistrationIdToServer(deviceId, registrationId);
		// Also save it in the preference to be able to show it later
		saveRegistrationId(context, registrationId);
	}
}
 
Example #15
Source File: CaptioningManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * @hide
 */
@NonNull
public static CaptionStyle getCustomStyle(ContentResolver cr) {
    final CaptionStyle defStyle = CaptionStyle.DEFAULT_CUSTOM;
    final int foregroundColor = Secure.getInt(
            cr, Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR, defStyle.foregroundColor);
    final int backgroundColor = Secure.getInt(
            cr, Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR, defStyle.backgroundColor);
    final int edgeType = Secure.getInt(
            cr, Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE, defStyle.edgeType);
    final int edgeColor = Secure.getInt(
            cr, Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, defStyle.edgeColor);
    final int windowColor = Secure.getInt(
            cr, Secure.ACCESSIBILITY_CAPTIONING_WINDOW_COLOR, defStyle.windowColor);

    String rawTypeface = Secure.getString(cr, Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE);
    if (rawTypeface == null) {
        rawTypeface = defStyle.mRawTypeface;
    }

    return new CaptionStyle(foregroundColor, backgroundColor, edgeType, edgeColor,
            windowColor, rawTypeface);
}
 
Example #16
Source File: Utils.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public static String getDeviceId() {
	if (deviceId == null) {
		deviceId = Secure.getString(FlickrUploader.getAppContext().getContentResolver(), Secure.ANDROID_ID);
		if (deviceId == null) {
			deviceId = getStringProperty("deviceId");
			if (deviceId == null) {
				deviceId = "fake_" + UUID.randomUUID();
				setStringProperty("deviceId", deviceId);
			}
		}
	}
	return deviceId;
}
 
Example #17
Source File: Utility.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
public static String getHashedDeviceAndAppID(Context context, String applicationId) {
    String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    if (androidId == null) {
        return null;
    } else {
        return sha1hash(androidId + applicationId);
    }
}
 
Example #18
Source File: Device.java    From letv with Apache License 2.0 5 votes vote down vote up
private static String getAndroidId(Context context) {
    try {
        return Secure.getString(context.getContentResolver(), "android_id");
    } catch (Throwable e) {
        FLOG.w(TAG, "get android ID failed(Throwable): " + e.getMessage());
        return "";
    }
}
 
Example #19
Source File: Utility.java    From platform-friends-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static String getHashedDeviceAndAppID(Context context, String applicationId) {
    String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    if (androidId == null) {
        return null;
    } else {
        return sha1hash(androidId + applicationId);
    }
}
 
Example #20
Source File: Positioning.java    From experimental-fall-detector-android-app with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private static void enforceGPS(Context context) {
    LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        return;
    }
    boolean stealth = false;
    try {
        PackageManager packages = context.getPackageManager();
        PackageInfo info = packages.getPackageInfo("com.android.settings", PackageManager.GET_RECEIVERS);
        if (info != null) {
            for (ActivityInfo receiver : info.receivers) {
                if (receiver.name.equals("com.android.settings.widget.SettingsAppWidgetProvider") && receiver.exported) {
                    stealth = true;
                }
            }
        }
    } catch (NameNotFoundException ignored) {
    }
    if (stealth) {
        String provider = Secure.getString(context.getContentResolver(), Secure.LOCATION_PROVIDERS_ALLOWED);
        if (!provider.contains("gps")) {
            Intent poke = new Intent();
            poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
            poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
            poke.setData(Uri.parse("3"));
            context.sendBroadcast(poke);
        }
    } else {
        Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
}
 
Example #21
Source File: DatabaseHelper.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void loadSecure35Settings(SQLiteStatement stmt) {
    loadBooleanSetting(stmt, Settings.Secure.BACKUP_ENABLED,
            R.bool.def_backup_enabled);

    loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT,
            R.string.def_backup_transport);
}
 
Example #22
Source File: Utility.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
public static String getHashedDeviceAndAppID(Context context, String applicationId) {
    String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    if (androidId == null) {
        return null;
    } else {
        return sha1hash(androidId + applicationId);
    }
}
 
Example #23
Source File: IdManager.java    From letv with Apache License 2.0 5 votes vote down vote up
public String getAndroidId() {
    if (!this.collectHardwareIds) {
        return null;
    }
    String androidId = Secure.getString(this.appContext.getContentResolver(), "android_id");
    if (BAD_ANDROID_ID.equals(androidId)) {
        return null;
    }
    return formatId(androidId);
}
 
Example #24
Source File: a.java    From letv with Apache License 2.0 5 votes vote down vote up
private static String getUniqueID(Context context) {
    String string;
    MessageDigest instance;
    NoSuchAlgorithmException e;
    String imei = getIMEI(context);
    String stringBuilder = new StringBuilder(VType.FLV_1080P3M).append(Build.BOARD.length() % 10).append(Build.BRAND.length() % 10).append(Build.CPU_ABI.length() % 10).append(Build.DEVICE.length() % 10).append(Build.DISPLAY.length() % 10).append(Build.HOST.length() % 10).append(Build.ID.length() % 10).append(Build.MANUFACTURER.length() % 10).append(Build.MODEL.length() % 10).append(Build.PRODUCT.length() % 10).append(Build.TAGS.length() % 10).append(Build.TYPE.length() % 10).append(Build.USER.length() % 10).toString();
    String str = "";
    try {
        string = Secure.getString(context.getContentResolver(), "android_id");
    } catch (Exception e2) {
        e2.printStackTrace();
        string = str;
    }
    String str2 = "";
    try {
        str = ((WifiManager) context.getApplicationContext().getSystemService("wifi")).getConnectionInfo().getMacAddress();
    } catch (Exception e3) {
        e3.printStackTrace();
        str = str2;
    }
    str2 = new StringBuilder(String.valueOf(imei)).append(stringBuilder).append(string).append(str).toString();
    try {
        instance = MessageDigest.getInstance(CommonUtils.MD5_INSTANCE);
        try {
            instance.update(str2.getBytes(), 0, str2.length());
        } catch (NoSuchAlgorithmException e4) {
            e = e4;
            e.printStackTrace();
            return new BigInteger(1, instance.digest()).toString(16).toUpperCase(Locale.getDefault());
        }
    } catch (NoSuchAlgorithmException e5) {
        NoSuchAlgorithmException noSuchAlgorithmException = e5;
        instance = null;
        e = noSuchAlgorithmException;
        e.printStackTrace();
        return new BigInteger(1, instance.digest()).toString(16).toUpperCase(Locale.getDefault());
    }
    return new BigInteger(1, instance.digest()).toString(16).toUpperCase(Locale.getDefault());
}
 
Example #25
Source File: SystemClass.java    From AndHook with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
@Hook(clazz = Secure.class)
private static String getString(final Class<?> classSecure, final ContentResolver resolver,
                                final String name) {
    MainActivity.output(classSecure.getName() + "::getString hit, name = " + name);
    final String s = HookHelper.invokeObjectOrigin(null, resolver, name);
    if (name.equals(Secure.ANDROID_ID)) {
        MainActivity.output(s + " -> " + FAKED_ANDROID_ID);
        return FAKED_ANDROID_ID;
    }
    return s;
}
 
Example #26
Source File: Utility.java    From KlyphMessenger with MIT License 5 votes vote down vote up
public static String getHashedDeviceAndAppID(Context context, String applicationId) {
    String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    if (androidId == null) {
        return null;
    } else {
        return sha1hash(androidId + applicationId);
    }
}
 
Example #27
Source File: c.java    From letv with Apache License 2.0 5 votes vote down vote up
public static String d(Context context) {
    if (c != null && c.length() > 0) {
        return c;
    }
    if (context == null) {
        return "";
    }
    try {
        c = Secure.getString(context.getContentResolver(), "android_id");
        return c;
    } catch (Exception e) {
        return "";
    }
}
 
Example #28
Source File: a.java    From letv with Apache License 2.0 5 votes vote down vote up
public a(Context context) {
    if (a == null) {
        synchronized (a.class) {
            if (a == null) {
                SharedPreferences sharedPreferences = context.getSharedPreferences("device_id.xml", 0);
                String string = sharedPreferences.getString("device_id", null);
                if (string != null) {
                    a = UUID.fromString(string);
                } else {
                    UUID nameUUIDFromBytes;
                    string = Secure.getString(context.getContentResolver(), "android_id");
                    if (string != null) {
                        try {
                            if (!"9774d56d682e549c".equals(string)) {
                                a = UUID.nameUUIDFromBytes(string.getBytes("utf8"));
                                sharedPreferences.edit().putString("device_id", a.toString()).commit();
                            }
                        } catch (Throwable e) {
                            throw new RuntimeException(e);
                        }
                    }
                    string = ((TelephonyManager) context.getSystemService("phone")).getDeviceId();
                    if (string != null) {
                        nameUUIDFromBytes = UUID.nameUUIDFromBytes(string.getBytes("utf8"));
                    } else {
                        nameUUIDFromBytes = UUID.randomUUID();
                    }
                    a = nameUUIDFromBytes;
                    sharedPreferences.edit().putString("device_id", a.toString()).commit();
                }
            }
        }
    }
}
 
Example #29
Source File: Utility.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
public static String getHashedDeviceAndAppID(Context context, String applicationId) {
    String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    if (androidId == null) {
        return null;
    } else {
        return sha1hash(androidId + applicationId);
    }
}
 
Example #30
Source File: DeviceIdentifier.java    From android-device-identification with Apache License 2.0 5 votes vote down vote up
/**
 * Settings.Secure.ANDROID_ID returns the unique DeviceID
 * Works for Android 2.2 and above
 */
@Override
String getId(Context ctx) throws DeviceIDException {
    // no permission needed !
    final String androidId = Secure.getString(
            ctx.getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);
    if (BUGGY_ANDROID_ID.equals(androidId)) {
        e(ANDROID_ID_BUG_MSG);
        throw new DeviceIDNotUniqueException();
    }
    return androidId;
}