• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
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  *   https://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 package com.google.android.enterprise.connectedapps;
17 
18 
19 /** A profile which can be interacted with using the profile-aware SDK. */
20 public final class Profile {
21 
22   private static final int CURRENT_PROFILE_LEGACY_IDENTIFIER = 0;
23   private static final int OTHER_PROFILE_LEGACY_IDENTIFIER = 1;
24 
25   /** Recreate a {@link Profile} previously serialised using {@link #asInt()}. */
fromInt(int legacyProfileIdentifier)26   public static Profile fromInt(int legacyProfileIdentifier) {
27     return new Profile(legacyProfileIdentifier);
28   }
29 
30   // 0 for "current profile", 1 for "other profile"
31   // TODO(142042055): Refactor ProfileId so it is stable across profiles, so it can be
32   //  stored, and so it can represent profile types as well as specific profiles
33   private final int legacyProfileIdentifier;
34 
Profile(int legacyProfileIdentifier)35   private Profile(int legacyProfileIdentifier) {
36     this.legacyProfileIdentifier = legacyProfileIdentifier;
37   }
38 
39   /** Returns true if this {@link Profile} refers to the current profile. */
isCurrent()40   public boolean isCurrent() {
41     return legacyProfileIdentifier == CURRENT_PROFILE_LEGACY_IDENTIFIER;
42   }
43 
44   /** Returns true if this {@link Profile} refers to the other profile. */
isOther()45   public boolean isOther() {
46     return legacyProfileIdentifier == OTHER_PROFILE_LEGACY_IDENTIFIER;
47   }
48 
asInt()49   public int asInt() {
50     return legacyProfileIdentifier;
51   }
52 
53   @Override
equals(Object o)54   public boolean equals(Object o) {
55     if (this == o) {
56       return true;
57     }
58     if (o == null || getClass() != o.getClass()) {
59       return false;
60     }
61     Profile that = (Profile) o;
62     return legacyProfileIdentifier == that.legacyProfileIdentifier;
63   }
64 
65   @Override
hashCode()66   public int hashCode() {
67     return legacyProfileIdentifier;
68   }
69 }
70