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.ondevicepersonalization.services.data.user; 18 19 import android.content.res.Configuration; 20 21 import java.util.ArrayList; 22 import java.util.HashMap; 23 import java.util.List; 24 25 /** 26 * A singleton class that holds all most recent in-memory user signals. 27 */ 28 public final class RawUserData { 29 30 private static RawUserData sUserData = null; 31 private static final String TAG = "UserData"; 32 33 // The current system time in milliseconds. 34 public long timeMillis = 0; 35 36 // The device time zone +/- minutes offset from UTC. 37 public int utcOffset = 0; 38 39 // The device orientation. 40 public int orientation = Configuration.ORIENTATION_PORTRAIT; 41 42 // Available bytes in MB. 43 public int availableBytesMB = 0; 44 45 // Battery percentage. 46 public int batteryPct = 0; 47 48 // The 3-letter ISO-3166 country code 49 public Country country = Country.UNKNOWN; 50 51 // The 2-letter ISO-639 language code 52 public Language language = Language.UNKNOWN; 53 54 // Mobile carrier. 55 public Carrier carrier = Carrier.UNKNOWN; 56 57 // OS versions of the device. 58 public OSVersion osVersions = new OSVersion(); 59 60 // Connection type values. 61 public enum ConnectionType { 62 UNKNOWN, 63 ETHERNET, 64 WIFI, 65 CELLULAR_2G, 66 CELLULAR_3G, 67 CELLULAR_4G, 68 CELLULAR_5G 69 }; 70 71 // Connection type. 72 public ConnectionType connectionType = ConnectionType.UNKNOWN; 73 74 // Status if network is metered. False - not metered. True - metered. 75 public boolean networkMeteredStatus = false; 76 77 // Connection speed in kbps. 78 public int connectionSpeedKbps = 0; 79 80 // Device metrics values. 81 public DeviceMetrics deviceMetrics = new DeviceMetrics(); 82 83 // installed packages. 84 public List<AppInfo> appsInfo = new ArrayList<>(); 85 86 // A histogram of app usage: total times used per app in the last 30 days. 87 public HashMap<String, Long> appUsageHistory = new HashMap<>(); 88 89 // User's most recently available location information. 90 public LocationInfo currentLocation = new LocationInfo(); 91 92 /** 93 * A histogram of location history: total time spent per location in the last 30 days. 94 * Default precision level of locations is set to E4. 95 */ 96 public HashMap<LocationInfo, Long> locationHistory = new HashMap<>(); 97 RawUserData()98 private RawUserData() { } 99 100 /** Returns an instance of UserData. */ getInstance()101 public static RawUserData getInstance() { 102 synchronized (RawUserData.class) { 103 if (sUserData == null) { 104 sUserData = new RawUserData(); 105 } 106 return sUserData; 107 } 108 } 109 } 110