1 /* 2 * Copyright (C) 2019 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.server.utils.quota; 18 19 import android.annotation.NonNull; 20 import android.util.proto.ProtoOutputStream; 21 import android.util.quota.CategoryProto; 22 23 /** 24 * A category as defined by the (system) client. Categories are used to put UPTCs in different 25 * groups. A sample group of Categories could be the various App Standby buckets or foreground vs 26 * background. 27 * 28 * @see Uptc 29 */ 30 public final class Category { 31 /** 32 * A {@link Category} that can be used if every app should be treated the same (given the same 33 * category). 34 */ 35 public static final Category SINGLE_CATEGORY = new Category("SINGLE"); 36 37 @NonNull 38 private final String mName; 39 40 private final int mHash; 41 42 /** Construct a new Category with the specified name. */ Category(@onNull String name)43 public Category(@NonNull String name) { 44 mName = name; 45 mHash = name.hashCode(); 46 } 47 48 /** {@inheritDoc} */ 49 @Override equals(Object other)50 public boolean equals(Object other) { 51 if (this == other) { 52 return true; 53 } 54 if (other instanceof Category) { 55 return this.mName.equals(((Category) other).mName); 56 } 57 return false; 58 } 59 60 /** {@inheritDoc} */ 61 @Override hashCode()62 public int hashCode() { 63 return mHash; 64 } 65 66 /** {@inheritDoc} */ 67 @Override toString()68 public String toString() { 69 return "Category{" + mName + "}"; 70 } 71 dumpDebug(ProtoOutputStream proto, long fieldId)72 void dumpDebug(ProtoOutputStream proto, long fieldId) { 73 final long token = proto.start(fieldId); 74 proto.write(CategoryProto.NAME, mName); 75 proto.end(token); 76 } 77 } 78