forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Convert the last java file in Android CHIPTool to kotlin (p…
…roject-chip#25236) * Convert NetworkCredentialsParcelable.java to NetworkCredentialsParcelable.kt * Address review comments
- Loading branch information
1 parent
c6cadc8
commit a786665
Showing
2 changed files
with
149 additions
and
170 deletions.
There are no files selected for viewing
170 changes: 0 additions & 170 deletions
170
...oid/CHIPTool/app/src/main/java/com/google/chip/chiptool/NetworkCredentialsParcelable.java
This file was deleted.
Oops, something went wrong.
149 changes: 149 additions & 0 deletions
149
...droid/CHIPTool/app/src/main/java/com/google/chip/chiptool/NetworkCredentialsParcelable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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 com.google.chip.chiptool | ||
|
||
import android.os.Parcelable | ||
import android.os.Parcel | ||
import android.os.Parcelable.Creator | ||
|
||
/** Class for holding WiFi or Thread credentials, but not both. */ | ||
class NetworkCredentialsParcelable : Parcelable { | ||
var wiFiCredentials: WiFiCredentials? | ||
private set | ||
var threadCredentials: ThreadCredentials? | ||
private set | ||
|
||
private constructor( | ||
wifiCredentials: WiFiCredentials?, threadCredentials: ThreadCredentials? | ||
) { | ||
this.wiFiCredentials = wifiCredentials | ||
this.threadCredentials = threadCredentials | ||
} | ||
|
||
// Begin Parcelable implementation | ||
private constructor(parcel: Parcel) { | ||
wiFiCredentials = parcel.readParcelable(WiFiCredentials::class.java.classLoader) | ||
threadCredentials = parcel.readParcelable(ThreadCredentials::class.java.classLoader) | ||
} | ||
|
||
override fun describeContents(): Int { | ||
return 0 | ||
} | ||
|
||
override fun writeToParcel(out: Parcel, flags: Int) { | ||
out.writeParcelable(wiFiCredentials, 0) | ||
out.writeParcelable(threadCredentials, 0) | ||
} | ||
|
||
class WiFiCredentials : Parcelable { | ||
val ssid: String? | ||
val password: String? | ||
|
||
constructor(ssid: String?, password: String?) { | ||
this.ssid = ssid | ||
this.password = password | ||
} | ||
|
||
// Begin Parcelable implementation | ||
private constructor(parcel: Parcel) { | ||
ssid = parcel.readString() | ||
password = parcel.readString() | ||
} | ||
|
||
override fun describeContents(): Int { | ||
return 0 | ||
} | ||
|
||
override fun writeToParcel(out: Parcel, flags: Int) { | ||
out.writeString(ssid) | ||
out.writeString(password) | ||
} | ||
|
||
companion object CREATOR : Parcelable.Creator<WiFiCredentials?> { | ||
override fun createFromParcel(parcel: Parcel): WiFiCredentials? { | ||
return WiFiCredentials(parcel) | ||
} | ||
|
||
override fun newArray(size: Int): Array<WiFiCredentials?> { | ||
return arrayOfNulls(size) | ||
} | ||
} | ||
} | ||
|
||
class ThreadCredentials : Parcelable { | ||
val operationalDataset: ByteArray | ||
|
||
constructor(operationalDataset: ByteArray) { | ||
this.operationalDataset = operationalDataset | ||
} | ||
|
||
// Begin Parcelable implementation | ||
private constructor(parcel: Parcel) { | ||
operationalDataset = ByteArray(parcel.readInt()) | ||
parcel.readByteArray(operationalDataset) | ||
} | ||
|
||
override fun describeContents(): Int { | ||
return 0 | ||
} | ||
|
||
override fun writeToParcel(out: Parcel, flags: Int) { | ||
out.writeInt(operationalDataset.size) | ||
out.writeByteArray(operationalDataset) | ||
} | ||
|
||
companion object CREATOR : Parcelable.Creator<ThreadCredentials?> { | ||
override fun createFromParcel(parcel: Parcel): ThreadCredentials? { | ||
return ThreadCredentials(parcel) | ||
} | ||
|
||
override fun newArray(size: Int): Array<ThreadCredentials?> { | ||
return arrayOfNulls(size) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
/** | ||
* Return a NetworkCredentialsParcelable object with the given WiFiCredentials and null | ||
* ThreadCredentials. | ||
*/ | ||
fun forWiFi(wifiCredentials: WiFiCredentials?): NetworkCredentialsParcelable { | ||
return NetworkCredentialsParcelable(wifiCredentials, null) | ||
} | ||
|
||
/** | ||
* Return a NetworkCredentialsParcelable object with the given ThreadCredentials and null | ||
* WiFiCredentials. | ||
*/ | ||
fun forThread(threadCredentials: ThreadCredentials?): NetworkCredentialsParcelable { | ||
return NetworkCredentialsParcelable(null, threadCredentials) | ||
} | ||
|
||
@JvmField | ||
val CREATOR = object : Parcelable.Creator<NetworkCredentialsParcelable?> { | ||
override fun createFromParcel(parcel: Parcel): NetworkCredentialsParcelable? { | ||
return NetworkCredentialsParcelable(parcel) | ||
} | ||
|
||
override fun newArray(size: Int): Array<NetworkCredentialsParcelable?> { | ||
return arrayOfNulls(size) | ||
} | ||
} | ||
} | ||
} |