Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ac47949 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Alter MODEL name with an extra space

parent 59439236
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;

import com.android.internal.safetynet.SafetyNetHooks;

/**
 * Base class for implementing application instrumentation code.  When running
 * with instrumentation turned on, this class will be instantiated for you
@@ -1154,6 +1156,7 @@ public class Instrumentation {
        Application app = getFactory(context.getPackageName())
                .instantiateApplication(cl, className);
        app.attach(context);
        SafetyNetHooks.init(app);
        return app;
    }
    
@@ -1171,6 +1174,7 @@ public class Instrumentation {
            ClassNotFoundException {
        Application app = (Application)clazz.newInstance();
        app.attach(context);
        SafetyNetHooks.init(app);
        return app;
    }

+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.safetynet;

import java.lang.reflect.Field;
import java.util.Arrays;

import android.app.Application;
import android.os.Build;
import android.util.Log;

public final class SafetyNetHooks {

    private static final String TAG = "SafetyNetHooks";
    private static final String GMS_PACKAGE_NAME = "com.google.android.gms";

    private static void setBuildField(String key, String value) {
        try {
            Field field = Build.class.getDeclaredField(key);
            field.setAccessible(true);
            field.set(null, value);
            field.setAccessible(false);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            Log.e(TAG, "Failed to fake Build." + key, e);
        }
    }

    public static void init(Application app) {
        if (GMS_PACKAGE_NAME.equals(app.getPackageName())) {
            setBuildField("MODEL", Build.MODEL + " ");
        }
    }
}