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

Commit 91a39d12 authored by Todd Kennedy's avatar Todd Kennedy
Browse files

Move BasePermission to own package

This is the first of many changes. Moving permissions to their own package.

Change-Id: I60e94e2da3c96788fc165e97e813ab5b9ee51586
Bug: 63539144
Test: Manual. Builds and runs
Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.PermissionsHostTest
Test: cts-tradefed run commandAndExit cts-dev -m CtsPermissionTestCases
Test: cts-tradefed run commandAndExit cts-dev -m CtsPermission2TestCases
parent f2b26597
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -318,16 +318,19 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
        return null;
    }

    @Override
    public String toString() {
        return "PermissionInfo{"
            + Integer.toHexString(System.identityHashCode(this))
            + " " + name + "}";
    }

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

    @Override
    public void writeToParcel(Parcel dest, int parcelableFlags) {
        super.writeToParcel(dest, parcelableFlags);
        dest.writeInt(protectionLevel);
@@ -338,11 +341,25 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable {
        TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
    }

    /** @hide */
    public int calculateFootprint() {
        int size = name.length();
        if (nonLocalizedLabel != null) {
            size += nonLocalizedLabel.length();
        }
        if (nonLocalizedDescription != null) {
            size += nonLocalizedDescription.length();
        }
        return size;
    }

    public static final Creator<PermissionInfo> CREATOR =
        new Creator<PermissionInfo>() {
        @Override
        public PermissionInfo createFromParcel(Parcel source) {
            return new PermissionInfo(source);
        }
        @Override
        public PermissionInfo[] newArray(int size) {
            return new PermissionInfo[size];
        }
+0 −105
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 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.server.pm;

import android.content.pm.PackageParser;
import android.content.pm.PermissionInfo;
import android.os.UserHandle;

final class BasePermission {
    final static int TYPE_NORMAL = 0;

    final static int TYPE_BUILTIN = 1;

    final static int TYPE_DYNAMIC = 2;

    final String name;

    String sourcePackage;

    PackageSettingBase packageSetting;

    final int type;

    int protectionLevel;

    PackageParser.Permission perm;

    PermissionInfo pendingInfo;

    /** UID that owns the definition of this permission */
    int uid;

    /** Additional GIDs given to apps granted this permission */
    private int[] gids;

    /**
     * Flag indicating that {@link #gids} should be adjusted based on the
     * {@link UserHandle} the granted app is running as.
     */
    private boolean perUser;

    BasePermission(String _name, String _sourcePackage, int _type) {
        name = _name;
        sourcePackage = _sourcePackage;
        type = _type;
        // Default to most conservative protection level.
        protectionLevel = PermissionInfo.PROTECTION_SIGNATURE;
    }

    @Override
    public String toString() {
        return "BasePermission{" + Integer.toHexString(System.identityHashCode(this)) + " " + name
                + "}";
    }

    public void setGids(int[] gids, boolean perUser) {
        this.gids = gids;
        this.perUser = perUser;
    }

    public int[] computeGids(int userId) {
        if (perUser) {
            final int[] userGids = new int[gids.length];
            for (int i = 0; i < gids.length; i++) {
                userGids[i] = UserHandle.getUid(userId, gids[i]);
            }
            return userGids;
        } else {
            return gids;
        }
    }

    public boolean isRuntime() {
        return (protectionLevel & PermissionInfo.PROTECTION_MASK_BASE)
                == PermissionInfo.PROTECTION_DANGEROUS;
    }

    public boolean isDevelopment() {
        return (protectionLevel & PermissionInfo.PROTECTION_MASK_BASE)
                == PermissionInfo.PROTECTION_SIGNATURE
                && (protectionLevel & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0;
    }

    public boolean isInstant() {
        return (protectionLevel & PermissionInfo.PROTECTION_FLAG_INSTANT) != 0;
    }

    public boolean isRuntimeOnly() {
        return (protectionLevel & PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) != 0;
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ import android.util.Log;
import android.util.Slog;
import android.util.Xml;
import com.android.internal.util.XmlUtils;
import com.android.server.pm.permission.BasePermission;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

+95 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.server.pm;

public final class DumpState {
    public static final int DUMP_LIBS = 1 << 0;
    public static final int DUMP_FEATURES = 1 << 1;
    public static final int DUMP_ACTIVITY_RESOLVERS = 1 << 2;
    public static final int DUMP_SERVICE_RESOLVERS = 1 << 3;
    public static final int DUMP_RECEIVER_RESOLVERS = 1 << 4;
    public static final int DUMP_CONTENT_RESOLVERS = 1 << 5;
    public static final int DUMP_PERMISSIONS = 1 << 6;
    public static final int DUMP_PACKAGES = 1 << 7;
    public static final int DUMP_SHARED_USERS = 1 << 8;
    public static final int DUMP_MESSAGES = 1 << 9;
    public static final int DUMP_PROVIDERS = 1 << 10;
    public static final int DUMP_VERIFIERS = 1 << 11;
    public static final int DUMP_PREFERRED = 1 << 12;
    public static final int DUMP_PREFERRED_XML = 1 << 13;
    public static final int DUMP_KEYSETS = 1 << 14;
    public static final int DUMP_VERSION = 1 << 15;
    public static final int DUMP_INSTALLS = 1 << 16;
    public static final int DUMP_INTENT_FILTER_VERIFIERS = 1 << 17;
    public static final int DUMP_DOMAIN_PREFERRED = 1 << 18;
    public static final int DUMP_FROZEN = 1 << 19;
    public static final int DUMP_DEXOPT = 1 << 20;
    public static final int DUMP_COMPILER_STATS = 1 << 21;
    public static final int DUMP_CHANGES = 1 << 22;
    public static final int DUMP_VOLUMES = 1 << 23;

    public static final int OPTION_SHOW_FILTERS = 1 << 0;

    private int mTypes;

    private int mOptions;

    private boolean mTitlePrinted;

    private SharedUserSetting mSharedUser;

    public boolean isDumping(int type) {
        if (mTypes == 0 && type != DUMP_PREFERRED_XML) {
            return true;
        }

        return (mTypes & type) != 0;
    }

    public void setDump(int type) {
        mTypes |= type;
    }

    public boolean isOptionEnabled(int option) {
        return (mOptions & option) != 0;
    }

    public void setOptionEnabled(int option) {
        mOptions |= option;
    }

    public boolean onTitlePrinted() {
        final boolean printed = mTitlePrinted;
        mTitlePrinted = true;
        return printed;
    }

    public boolean getTitlePrinted() {
        return mTitlePrinted;
    }

    public void setTitlePrinted(boolean enabled) {
        mTitlePrinted = enabled;
    }

    public SharedUserSetting getSharedUser() {
        return mSharedUser;
    }

    public void setSharedUser(SharedUserSetting user) {
        mSharedUser = user;
    }
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ import com.android.internal.os.BackgroundThread;
import com.android.internal.os.SomeArgs;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.XmlUtils;
import com.android.server.pm.permission.BasePermission;

import libcore.io.IoUtils;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
Loading