1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.bedstead.nene.appops; 18 19 /** Valid modes for an AppOp. */ 20 public enum AppOpsMode { 21 ALLOWED(/* MODE_ALLOWED */ 0), 22 IGNORED(/* MODE_IGNORED */ 1), 23 ERRORED(/* MODE_ERRORED */ 2), 24 DEFAULT(/* MODE_DEFAULT */ 3), 25 FOREGROUND(/* MODE_FOREGROUND */ 4); 26 27 // Values from AppOpsManager 28 private static final int MODE_ALLOWED = 0; 29 private static final int MODE_IGNORED = 1; 30 private static final int MODE_ERRORED = 2; 31 private static final int MODE_DEFAULT = 3; 32 private static final int MODE_FOREGROUND = 4; 33 34 final int mValue; 35 36 /** The {@code AppOpsManager} equivalent value. */ value()37 public int value() { 38 return mValue; 39 } 40 AppOpsMode(int value)41 AppOpsMode(int value) { 42 this.mValue = value; 43 } 44 forValue(int value)45 static AppOpsMode forValue(int value) { 46 switch (value) { 47 case MODE_ALLOWED: 48 return ALLOWED; 49 case MODE_IGNORED: 50 return IGNORED; 51 case MODE_ERRORED: 52 return ERRORED; 53 case MODE_DEFAULT: 54 return DEFAULT; 55 case MODE_FOREGROUND: 56 return FOREGROUND; 57 default: 58 throw new IllegalStateException("Unknown AppOpsMode"); 59 } 60 } 61 } 62