• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.locales;
18 
19 import static android.os.Process.INVALID_UID;
20 
21 import com.android.internal.util.FrameworkStatsLog;
22 
23 import java.util.Locale;
24 
25 /**
26  * Holds data used to report the ApplicationLocalesChanged atom.
27  */
28 public final class AppLocaleChangedAtomRecord {
29     private static final String DEFAULT_PREFIX = "default-";
30     final int mCallingUid;
31     int mTargetUid = INVALID_UID;
32     String mNewLocales = DEFAULT_PREFIX;
33     String mPrevLocales = DEFAULT_PREFIX;
34     int mStatus = FrameworkStatsLog
35             .APPLICATION_LOCALES_CHANGED__STATUS__STATUS_UNSPECIFIED;
36     int mCaller = FrameworkStatsLog
37             .APPLICATION_LOCALES_CHANGED__CALLER__CALLER_UNKNOWN;
AppLocaleChangedAtomRecord(int callingUid)38     AppLocaleChangedAtomRecord(int callingUid) {
39         this.mCallingUid = callingUid;
40         Locale defaultLocale = Locale.getDefault();
41         if (defaultLocale != null) {
42             this.mNewLocales = DEFAULT_PREFIX + defaultLocale.toLanguageTag();
43             this.mPrevLocales = DEFAULT_PREFIX + defaultLocale.toLanguageTag();
44         }
45     }
46 
setNewLocales(String newLocales)47     void setNewLocales(String newLocales) {
48         this.mNewLocales = convertEmptyLocales(newLocales);
49     }
50 
setTargetUid(int targetUid)51     void setTargetUid(int targetUid) {
52         this.mTargetUid = targetUid;
53     }
54 
setPrevLocales(String prevLocales)55     void setPrevLocales(String prevLocales) {
56         this.mPrevLocales = convertEmptyLocales(prevLocales);
57     }
58 
setStatus(int status)59     void setStatus(int status) {
60         this.mStatus = status;
61     }
62 
setCaller(int caller)63     void setCaller(int caller) {
64         this.mCaller = caller;
65     }
66 
convertEmptyLocales(String locales)67     private String convertEmptyLocales(String locales) {
68         String target = locales;
69         if ("".equals(locales)) {
70             Locale defaultLocale = Locale.getDefault();
71             if (defaultLocale != null) {
72                 target = DEFAULT_PREFIX + defaultLocale.toLanguageTag();
73             }
74         }
75 
76         return target;
77     }
78 }
79