1 /*
2  * Copyright (C) 2017 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.loganalysis.item;
18 
19 import org.json.JSONException;
20 import org.json.JSONObject;
21 
22 import java.util.Map;
23 
24 /** An {@link IItem} used to store apps and their version codes and names. */
25 public class DumpsysPackageStatsItem extends GenericMapItem<AppVersionItem> {
26     private static final long serialVersionUID = 1L;
27 
28     /** Constant for JSON output */
29     public static final String APP_VERSIONS = "APP_VERSIONS";
30 
31     /** {@inheritDoc} */
32     @Override
toJson()33     public JSONObject toJson() {
34         JSONObject object = new JSONObject();
35         try {
36             JSONObject appVersions = new JSONObject();
37             for (Map.Entry<String, AppVersionItem> entry : entrySet()) {
38                 appVersions.put(entry.getKey(), entry.getValue().toJson());
39             }
40             object.put(APP_VERSIONS, appVersions);
41         } catch (JSONException e) {
42             // Ignore
43         }
44         return object;
45     }
46 }
47