|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 The Pixel Experience Project |
| 3 | + * 2021 crDroid Android Project |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.android.internal.util.crdroid; |
| 19 | + |
| 20 | +import android.os.Build; |
| 21 | +import android.util.Log; |
| 22 | + |
| 23 | +import java.util.Arrays; |
| 24 | +import java.lang.reflect.Field; |
| 25 | +import java.util.HashMap; |
| 26 | +import java.util.Map; |
| 27 | + |
| 28 | +public class PixelPropsUtils { |
| 29 | + |
| 30 | + private static final String TAG = PixelPropsUtils.class.getSimpleName(); |
| 31 | + private static final boolean DEBUG = false; |
| 32 | + |
| 33 | + private static final Map<String, Object> propsToChange; |
| 34 | + |
| 35 | + private static final String[] packagesToChange = { |
| 36 | + "com.google.android.apps.safetyhub", |
| 37 | + "com.google.android.apps.turbo", |
| 38 | + "com.google.android.apps.wallpaper", |
| 39 | + "com.google.android.apps.maps", |
| 40 | + "com.google.android.gms", |
| 41 | + "com.google.android.googlequicksearchbox" |
| 42 | + }; |
| 43 | + |
| 44 | + static { |
| 45 | + propsToChange = new HashMap<>(); |
| 46 | + propsToChange.put("BRAND", "google"); |
| 47 | + propsToChange.put("MANUFACTURER", "Google"); |
| 48 | + propsToChange.put("DEVICE", "redfin"); |
| 49 | + propsToChange.put("PRODUCT", "redfin"); |
| 50 | + propsToChange.put("MODEL", "Pixel 5"); |
| 51 | + propsToChange.put("FINGERPRINT", "google/redfin/redfin:11/RQ2A.210305.007/7124944:user/release-keys"); |
| 52 | + } |
| 53 | + |
| 54 | + public static void setProps(String packageName) { |
| 55 | + if (packageName == null) { |
| 56 | + return; |
| 57 | + } |
| 58 | + if (Arrays.asList(packagesToChange).contains(packageName)) { |
| 59 | + if (DEBUG) { |
| 60 | + Log.d(TAG, "Defining props for: " + packageName); |
| 61 | + } |
| 62 | + for (Map.Entry<String, Object> prop : propsToChange.entrySet()) { |
| 63 | + String key = prop.getKey(); |
| 64 | + Object value = prop.getValue(); |
| 65 | + setPropValue(key, value); |
| 66 | + } |
| 67 | + } |
| 68 | + // Set proper indexing fingerprint |
| 69 | + if (packageName.equals("com.google.android.settings.intelligence")) { |
| 70 | + setPropValue("FINGERPRINT", Build.DATE); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + private static void setPropValue(String key, Object value) { |
| 75 | + try { |
| 76 | + if (DEBUG) { |
| 77 | + Log.d(TAG, "Defining prop " + key + " to " + value.toString()); |
| 78 | + } |
| 79 | + Field field = Build.class.getDeclaredField(key); |
| 80 | + field.setAccessible(true); |
| 81 | + field.set(null, value); |
| 82 | + field.setAccessible(false); |
| 83 | + } catch (NoSuchFieldException | IllegalAccessException e) { |
| 84 | + Log.e(TAG, "Failed to set prop " + key, e); |
| 85 | + } |
| 86 | + } |
| 87 | +} |
0 commit comments