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

Commit ee6b8f7b authored by Hani Kazmi's avatar Hani Kazmi
Browse files

[AAPM] Add Feature class

The settings screen for advanced protection will list the protection
features available on the device during onboarding. This list is dynamic,
and provided by the service. The list can be added to be Hooks, which
are features living directly in the advanced protection package, and by
Providers, where the feature lives elsewhere and returns the available
protections.

Bug: 352420507
Test: atest AdvancedProtectionServiceTest AdvancedProtectionManagerTest
Flag: android.security.aapm_api
Change-Id: Iaa3e8fd77a78582c7676b59c7c47d3dd7db50027
parent 4cd87c23
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -39735,7 +39735,7 @@ package android.security {
package android.security.advancedprotection {
  @FlaggedApi("android.security.aapm_api") public class AdvancedProtectionManager {
  @FlaggedApi("android.security.aapm_api") public final class AdvancedProtectionManager {
    method @RequiresPermission(android.Manifest.permission.QUERY_ADVANCED_PROTECTION_MODE) public boolean isAdvancedProtectionEnabled();
    method @RequiresPermission(android.Manifest.permission.QUERY_ADVANCED_PROTECTION_MODE) public void registerAdvancedProtectionCallback(@NonNull java.util.concurrent.Executor, @NonNull android.security.advancedprotection.AdvancedProtectionManager.Callback);
    method @RequiresPermission(android.Manifest.permission.QUERY_ADVANCED_PROTECTION_MODE) public void unregisterAdvancedProtectionCallback(@NonNull android.security.advancedprotection.AdvancedProtectionManager.Callback);
+10 −1
Original line number Diff line number Diff line
@@ -12336,7 +12336,16 @@ package android.security {
package android.security.advancedprotection {
  @FlaggedApi("android.security.aapm_api") public class AdvancedProtectionManager {
  @FlaggedApi("android.security.aapm_api") public final class AdvancedProtectionFeature implements android.os.Parcelable {
    ctor public AdvancedProtectionFeature(@NonNull String);
    method public int describeContents();
    method @NonNull public String getId();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.security.advancedprotection.AdvancedProtectionFeature> CREATOR;
  }
  @FlaggedApi("android.security.aapm_api") public final class AdvancedProtectionManager {
    method @NonNull @RequiresPermission(android.Manifest.permission.SET_ADVANCED_PROTECTION_MODE) public java.util.List<android.security.advancedprotection.AdvancedProtectionFeature> getAdvancedProtectionFeatures();
    method @RequiresPermission(android.Manifest.permission.SET_ADVANCED_PROTECTION_MODE) public void setAdvancedProtectionEnabled(boolean);
  }
+23 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 android.security.advancedprotection;

/**
 * Represents an advanced protection feature providing protections
 * @hide
 */
parcelable AdvancedProtectionFeature;
 No newline at end of file
+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 android.security.advancedprotection;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.security.Flags;

/**
 * An advanced protection feature providing protections.
 * @hide
 */
@FlaggedApi(Flags.FLAG_AAPM_API)
@SystemApi
public final class AdvancedProtectionFeature implements Parcelable {
    private final String mId;

    /**
     * Create an object identifying an Advanced Protection feature for AdvancedProtectionManager
     * @param id A unique ID to identify this feature. It is used by Settings screens to display
     *           information about this feature.
     */
    public AdvancedProtectionFeature(@NonNull String id) {
        mId = id;
    }

    private AdvancedProtectionFeature(Parcel in) {
        mId = in.readString8();
    }

    /**
     * @return the unique ID representing this feature
     */
    @NonNull
    public String getId() {
        return mId;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString8(mId);
    }

    @NonNull
    public static final Parcelable.Creator<AdvancedProtectionFeature> CREATOR =
            new Parcelable.Creator<>() {
                public AdvancedProtectionFeature createFromParcel(Parcel in) {
                    return new AdvancedProtectionFeature(in);
                }

                public AdvancedProtectionFeature[] newArray(int size) {
                    return new AdvancedProtectionFeature[size];
                }
            };
}
+18 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.RemoteException;
import android.security.Flags;
import android.util.Log;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;

@@ -41,7 +42,7 @@ import java.util.concurrent.Executor;
 */
@FlaggedApi(Flags.FLAG_AAPM_API)
@SystemService(Context.ADVANCED_PROTECTION_SERVICE)
public class AdvancedProtectionManager {
public final class AdvancedProtectionManager {
    private static final String TAG = "AdvancedProtectionMgr";

    private final ConcurrentHashMap<Callback, IAdvancedProtectionCallback>
@@ -146,6 +147,22 @@ public class AdvancedProtectionManager {
        }
    }

    /**
     * Returns the list of advanced protection features which are available on this device.
     *
     * @hide
     */
    @SystemApi
    @NonNull
    @RequiresPermission(Manifest.permission.SET_ADVANCED_PROTECTION_MODE)
    public List<AdvancedProtectionFeature> getAdvancedProtectionFeatures() {
        try {
            return mService.getAdvancedProtectionFeatures();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * A callback class for monitoring changes to Advanced Protection state
     *
Loading