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

Commit 1573877a authored by Oli Lan's avatar Oli Lan
Browse files

Rename ApexContext to ApexEnvironment.

This renames the new ApexContext class to ApexEnvironment, at the
request of the API Council.

Bug: 150685788
Test: atest ApexEnvironmentTest
Change-Id: I4340b0c7e78d240f4e48fdc94ec9e7d60e58d35c
parent baed20e4
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.permission.persistence;

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

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

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

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

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

    private final String mApexModuleName;

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

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

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

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

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

        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",
                apexContext.getCredentialProtectedDataDirForUser(
                apexEnvironment.getCredentialProtectedDataDirForUser(
                        UserHandle.of(16)).getAbsolutePath());
    }
}