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

Commit 86fe0229 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Rename ApexContext to ApexEnvironment." into rvc-dev am: e6dbe2b8

Change-Id: Id9e747701e0fa9c1b2bee5fac14b289d465c8efc
parents 6c5dedad e6dbe2b8
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.permission.persistence;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.content.ApexContext;
import android.content.ApexEnvironment;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArrayMap;
@@ -258,8 +258,8 @@ public class RuntimePermissionsPersistenceImpl implements RuntimePermissionsPers


    @NonNull
    @NonNull
    private static File getFile(@NonNull UserHandle user) {
    private static File getFile(@NonNull UserHandle user) {
        ApexContext apexContext = ApexContext.getApexContext(APEX_MODULE_NAME);
        ApexEnvironment apexEnvironment = ApexEnvironment.getApexEnvironment(APEX_MODULE_NAME);
        File dataDirectory = apexContext.getDeviceProtectedDataDirForUser(user);
        File dataDirectory = apexEnvironment.getDeviceProtectedDataDirForUser(user);
        return new File(dataDirectory, RUNTIME_PERMISSIONS_FILE_NAME);
        return new File(dataDirectory, RUNTIME_PERMISSIONS_FILE_NAME);
    }
    }
}
}
+3 −3
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.role.persistence;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.content.ApexContext;
import android.content.ApexEnvironment;
import android.os.UserHandle;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.ArraySet;
@@ -211,8 +211,8 @@ public class RolesPersistenceImpl implements RolesPersistence {


    @NonNull
    @NonNull
    private static File getFile(@NonNull UserHandle user) {
    private static File getFile(@NonNull UserHandle user) {
        ApexContext apexContext = ApexContext.getApexContext(APEX_MODULE_NAME);
        ApexEnvironment apexEnvironment = ApexEnvironment.getApexEnvironment(APEX_MODULE_NAME);
        File dataDirectory = apexContext.getDeviceProtectedDataDirForUser(user);
        File dataDirectory = apexEnvironment.getDeviceProtectedDataDirForUser(user);
        return new File(dataDirectory, ROLES_FILE_NAME);
        return new File(dataDirectory, ROLES_FILE_NAME);
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -1759,8 +1759,8 @@ package android.companion {
package android.content {
package android.content {
  public class ApexContext {
  public class ApexEnvironment {
    method @NonNull public static android.content.ApexContext getApexContext(@NonNull String);
    method @NonNull public static android.content.ApexEnvironment getApexEnvironment(@NonNull String);
    method @NonNull public java.io.File getCredentialProtectedDataDirForUser(@NonNull android.os.UserHandle);
    method @NonNull public java.io.File getCredentialProtectedDataDirForUser(@NonNull android.os.UserHandle);
    method @NonNull public java.io.File getDeviceProtectedDataDir();
    method @NonNull public java.io.File getDeviceProtectedDataDir();
    method @NonNull public java.io.File getDeviceProtectedDataDirForUser(@NonNull android.os.UserHandle);
    method @NonNull public java.io.File getDeviceProtectedDataDirForUser(@NonNull android.os.UserHandle);
+10 −10
Original line number Original line Diff line number Diff line
@@ -30,29 +30,29 @@ import java.util.Objects;
 * @hide
 * @hide
 */
 */
@SystemApi
@SystemApi
public class ApexContext {
public class ApexEnvironment {


    private static final String APEX_DATA = "apexdata";
    private static final String APEX_DATA = "apexdata";


    /**
    /**
     * Returns an ApexContext instance for the APEX with the provided {@code apexModuleName}.
     * Returns an ApexEnvironment instance for the APEX with the provided {@code apexModuleName}.
     *
     *
     * <p>To preserve the safety and integrity of APEX modules, you must only obtain the ApexContext
     * <p>To preserve the safety and integrity of APEX modules, you must only obtain the
     * for your specific APEX, and you <em>must never</em> attempt to obtain an ApexContext for
     * ApexEnvironment for your specific APEX, and you <em>must never</em> attempt to obtain an
     * another APEX.  Any coordination between APEXs must be performed through well-defined
     * ApexEnvironment for another APEX.  Any coordination between APEXs must be performed through
     * interfaces; attempting to directly read or write raw files belonging to another APEX will
     * well-defined interfaces; attempting to directly read or write raw files belonging to another
     * violate the hermetic storage requirements placed upon each module.
     * APEX will violate the hermetic storage requirements placed upon each module.
     */
     */
    @NonNull
    @NonNull
    public static ApexContext getApexContext(@NonNull String apexModuleName) {
    public static ApexEnvironment getApexEnvironment(@NonNull String apexModuleName) {
        Objects.requireNonNull(apexModuleName, "apexModuleName cannot be null");
        Objects.requireNonNull(apexModuleName, "apexModuleName cannot be null");
        //TODO(b/141148175): Check that apexModuleName is an actual APEX name
        //TODO(b/141148175): Check that apexModuleName is an actual APEX name
        return new ApexContext(apexModuleName);
        return new ApexEnvironment(apexModuleName);
    }
    }


    private final String mApexModuleName;
    private final String mApexModuleName;


    private ApexContext(String apexModuleName) {
    private ApexEnvironment(String apexModuleName) {
        mApexModuleName = apexModuleName;
        mApexModuleName = apexModuleName;
    }
    }


+6 −5
Original line number Original line Diff line number Diff line
@@ -28,20 +28,21 @@ import org.junit.runner.RunWith;


@SmallTest
@SmallTest
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
public class ApexContextTest {
public class ApexEnvironmentTest {


    @Test
    @Test
    public void dataDirectoryPathsAreAsExpected() {
    public void dataDirectoryPathsAreAsExpected() {
        ApexContext apexContext = ApexContext.getApexContext("my.apex");
        ApexEnvironment apexEnvironment = ApexEnvironment.getApexEnvironment("my.apex");


        assertEquals("/data/misc/apexdata/my.apex",
        assertEquals("/data/misc/apexdata/my.apex",
                apexContext.getDeviceProtectedDataDir().getAbsolutePath());
                apexEnvironment.getDeviceProtectedDataDir().getAbsolutePath());


        assertEquals("/data/misc_de/5/apexdata/my.apex",
        assertEquals("/data/misc_de/5/apexdata/my.apex",
                apexContext.getDeviceProtectedDataDirForUser(UserHandle.of(5)).getAbsolutePath());
                apexEnvironment
                        .getDeviceProtectedDataDirForUser(UserHandle.of(5)).getAbsolutePath());


        assertEquals("/data/misc_ce/16/apexdata/my.apex",
        assertEquals("/data/misc_ce/16/apexdata/my.apex",
                apexContext.getCredentialProtectedDataDirForUser(
                apexEnvironment.getCredentialProtectedDataDirForUser(
                        UserHandle.of(16)).getAbsolutePath());
                        UserHandle.of(16)).getAbsolutePath());
    }
    }
}
}