• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #include <android/content/ComponentName.h>
18 
19 namespace android {
20 namespace content {
21 
ComponentName()22 ComponentName::ComponentName()
23         :mPackage(),
24          mClass() {
25 }
26 
ComponentName(const ComponentName & that)27 ComponentName::ComponentName(const ComponentName& that)
28         :mPackage(that.mPackage),
29          mClass(that.mClass) {
30 }
31 
ComponentName(const string & pkg,const string & cls)32 ComponentName::ComponentName(const string& pkg, const string& cls)
33         :mPackage(pkg),
34          mClass(cls) {
35 }
36 
~ComponentName()37 ComponentName::~ComponentName() {
38 }
39 
operator <(const ComponentName & that) const40 bool ComponentName::operator<(const ComponentName& that) const {
41     if (mPackage < that.mPackage) {
42        return true;
43     } else if (mPackage > that.mPackage) {
44        return false;
45     }
46     return mClass < that.mClass;
47 }
48 
readFromParcel(const Parcel * in)49 status_t ComponentName::readFromParcel(const Parcel* in) {
50     status_t err;
51 
52     // Note: This is a subtle variation from the java version, which
53     // requires non-null strings, but does not require non-empty strings.
54     // This code implicitly requires non-null strings, because it's impossible,
55     // but reading null strings that were somehow written by the java
56     // code would turn them into empty strings.
57 
58     err = in->readUtf8FromUtf16(&mPackage);
59     if (err != NO_ERROR) {
60         return err;
61     }
62 
63     err = in->readUtf8FromUtf16(&mClass);
64     if (err != NO_ERROR) {
65         return err;
66     }
67 
68     return NO_ERROR;
69 }
70 
writeToParcel(android::Parcel * out) const71 status_t ComponentName::writeToParcel(android::Parcel* out) const {
72     status_t err;
73 
74     err = out->writeUtf8AsUtf16(mPackage);
75     if (err != NO_ERROR) {
76         return err;
77     }
78 
79     err = out->writeUtf8AsUtf16(mClass);
80     if (err != NO_ERROR) {
81         return err;
82     }
83 
84     return NO_ERROR;
85 }
86 
87 }} // namespace android::content
88 
89