1 /* 2 * Copyright (C) 2021 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.app; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.ComponentName; 22 import android.os.UserHandle; 23 import android.text.TextUtils; 24 25 import java.util.Objects; 26 27 /** 28 * Representation of a {@link android.service.games.GameService} provider configuration. 29 */ 30 final class GameServiceConfiguration { 31 private final String mPackageName; 32 @Nullable 33 private final GameServiceComponentConfiguration mGameServiceComponentConfiguration; 34 GameServiceConfiguration( @onNull String packageName, @Nullable GameServiceComponentConfiguration gameServiceComponentConfiguration)35 GameServiceConfiguration( 36 @NonNull String packageName, 37 @Nullable GameServiceComponentConfiguration gameServiceComponentConfiguration) { 38 Objects.requireNonNull(packageName); 39 40 mPackageName = packageName; 41 mGameServiceComponentConfiguration = gameServiceComponentConfiguration; 42 } 43 44 @NonNull getPackageName()45 public String getPackageName() { 46 return mPackageName; 47 } 48 49 @Nullable getGameServiceComponentConfiguration()50 public GameServiceComponentConfiguration getGameServiceComponentConfiguration() { 51 return mGameServiceComponentConfiguration; 52 } 53 54 @Override equals(Object o)55 public boolean equals(Object o) { 56 if (this == o) { 57 return true; 58 } 59 60 if (!(o instanceof GameServiceConfiguration)) { 61 return false; 62 } 63 64 GameServiceConfiguration that = (GameServiceConfiguration) o; 65 return TextUtils.equals(mPackageName, that.mPackageName) 66 && Objects.equals(mGameServiceComponentConfiguration, 67 that.mGameServiceComponentConfiguration); 68 } 69 70 @Override hashCode()71 public int hashCode() { 72 return Objects.hash(mPackageName, mGameServiceComponentConfiguration); 73 } 74 75 @Override toString()76 public String toString() { 77 return "GameServiceConfiguration{" 78 + "packageName=" 79 + mPackageName 80 + ", gameServiceComponentConfiguration=" 81 + mGameServiceComponentConfiguration 82 + '}'; 83 } 84 85 static final class GameServiceComponentConfiguration { 86 private final UserHandle mUserHandle; 87 private final ComponentName mGameServiceComponentName; 88 private final ComponentName mGameSessionServiceComponentName; 89 GameServiceComponentConfiguration( @onNull UserHandle userHandle, @NonNull ComponentName gameServiceComponentName, @NonNull ComponentName gameSessionServiceComponentName)90 GameServiceComponentConfiguration( 91 @NonNull UserHandle userHandle, @NonNull ComponentName gameServiceComponentName, 92 @NonNull ComponentName gameSessionServiceComponentName) { 93 Objects.requireNonNull(userHandle); 94 Objects.requireNonNull(gameServiceComponentName); 95 Objects.requireNonNull(gameSessionServiceComponentName); 96 97 mUserHandle = userHandle; 98 mGameServiceComponentName = gameServiceComponentName; 99 mGameSessionServiceComponentName = gameSessionServiceComponentName; 100 } 101 102 @NonNull getUserHandle()103 public UserHandle getUserHandle() { 104 return mUserHandle; 105 } 106 107 @NonNull getGameServiceComponentName()108 public ComponentName getGameServiceComponentName() { 109 return mGameServiceComponentName; 110 } 111 112 @NonNull getGameSessionServiceComponentName()113 public ComponentName getGameSessionServiceComponentName() { 114 return mGameSessionServiceComponentName; 115 } 116 117 @Override equals(Object o)118 public boolean equals(Object o) { 119 if (this == o) { 120 return true; 121 } 122 123 if (!(o instanceof GameServiceComponentConfiguration)) { 124 return false; 125 } 126 127 GameServiceComponentConfiguration that = 128 (GameServiceComponentConfiguration) o; 129 return mUserHandle.equals(that.mUserHandle) && mGameServiceComponentName.equals( 130 that.mGameServiceComponentName) 131 && mGameSessionServiceComponentName.equals( 132 that.mGameSessionServiceComponentName); 133 } 134 135 @Override hashCode()136 public int hashCode() { 137 return Objects.hash(mUserHandle, 138 mGameServiceComponentName, 139 mGameSessionServiceComponentName); 140 } 141 142 @Override toString()143 public String toString() { 144 return "GameServiceComponentConfiguration{" 145 + "userHandle=" 146 + mUserHandle 147 + ", gameServiceComponentName=" 148 + mGameServiceComponentName 149 + ", gameSessionServiceComponentName=" 150 + mGameSessionServiceComponentName 151 + "}"; 152 } 153 } 154 } 155